在一定时间后停止Android视频
我想在Android 5.1中以全屏模式播放一段视频,视频视图为在一定时间后停止Android视频,android,android-videoview,android-video-player,Android,Android Videoview,Android Video Player,我想在Android 5.1中以全屏模式播放一段视频,视频视图为VideoView。此外,我想在一段时间后(比如5分钟)停止视频(并更改活动)。我怎样才能做到这一点?我的布局如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/LinearLayout01" android:layout_height="fill_parent" android:paddi
VideoView
。此外,我想在一段时间后(比如5分钟)停止视频(并更改活动)。我怎样才能做到这一点?我的布局如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_height="fill_parent"
android:paddingLeft="2px"
android:paddingRight="2px"
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="2px"
android:paddingBottom="2px"
android:layout_width="fill_parent"
android:orientation="vertical">
<VideoView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/VideoView" />
</LinearLayout>
您应该使用“MediaPlayer”,然后使用“Runnable”将视频停止在5米。然后使用处理程序调用Runnable with“.postDelayed”方法,如下所示:
public class VideoViewDemo extends Activity {
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mp = MediaPlayer.create(this, "video");
mp.start();
Handler handler = new Handler();
handler.postDelayed(stopPlayerTask, 500000);
}
Runnable stopPlayerTask = new Runnable(){
@Override
public void run() {
mp.pause();
}};
}
您需要修改此示例;)可能重复的
public class VideoViewDemo extends Activity {
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mp = MediaPlayer.create(this, "video");
mp.start();
Handler handler = new Handler();
handler.postDelayed(stopPlayerTask, 500000);
}
Runnable stopPlayerTask = new Runnable(){
@Override
public void run() {
mp.pause();
}};
}