[英]my "video view" is blank when pressing the back button. How i can fix it?
So, i have a video view for my background.所以,我有一个视频视图作为我的背景。 There i put image view as button.我把图像视图作为按钮。 when i go to other activity and then go back, my video cannot play.当我 go 到其他活动然后 go 回来时,我的视频无法播放。 just blank.只是空白。 Sorry about my english.对不起我的英语。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pilih_user);
VideoView videoview = (VideoView) findViewById(R.id.videoView);
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.test);
videoview.setVideoURI(uri);
videoview.start();
ImageView apin = findViewById(R.id.pilihguru);
apin.setOnClickListener(view ->
{
Intent intent = new Intent(PilihUser.this, DaftarPembelajaran.class);
startActivity(intent);
});
}
}
And this my layout.这是我的布局。 I use constraint and then put video view as background.我使用约束,然后将视频视图作为背景。 This my first time to build simple app by java.这是我第一次通过 java 构建简单的应用程序。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layoutpilihuser"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bghome"
tools:context=".PilihUser">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="@+id/pilihanak"
android:layout_width="200dp"
android:layout_height="94dp"
android:layout_marginTop="64dp"
android:contentDescription="@string/app_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.499"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/videoView"
app:srcCompat="@drawable/pilihuser1" />
<ImageView
android:id="@+id/pilihguru"
android:layout_width="200dp"
android:layout_height="94dp"
android:layout_marginTop="28dp"
android:contentDescription="@string/app_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.499"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pilihanak"
app:srcCompat="@drawable/pilihuser2" />
</android.support.constraint.ConstraintLayout>
You need to call videoview.start() in onResume:您需要在 onResume 中调用 videoview.start():
@Override
public void onResume(){
super.onResume();
videoview.start();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.