/ / Zastavenie videa Android po určitom čase - Android, Android-videoview, Android-video-prehrávač

Zastavenie videa so systémom Android po určitom čase - android, android-videoview, android-video-player

Chcel by som si prehrať video so značkou VideoView v režime celej obrazovky v systéme Android 5.1. Okrem toho by som chcel video zastaviť (a zmeniť aktivitu) po určitom čase (povedzme 5 minút). Ako to môžem dosiahnuť? Moje rozloženie je toto:

<?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>

A nasledujúci kód:

import android.app.Activity;
import android.os.Bundle;
import android.widget.VideoView;

public class VideoViewDemo extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

VideoView videoView = (VideoView)findViewById(R.id.VideoView);

videoView.setVideoPath("/sdcard/test.mp4");

videoView.start();
}
}

odpovede:

1 pre odpoveď č. 1

Mali by ste použiť „MediaPlayer“ a potom vytvoriť „Runnable“ na zastavenie videa na 5 m. Potom pomocou obslužného programu zavoláte svoju Runnable pomocou metódy „.postDelayed“, ako je táto:

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();
}};
}

Tento príklad je potrebné prispôsobiť;)