我有一个视频应用程序。我需要应用程序按顺序播放视频(1、2、3、4、1、2、3、4),但是当我安装应用程序时,视频随机运行(2、3、1、4、2、1 ,3,4,2,4 等...)。
这是我的代码:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final VideoView videoView = (VideoView) findViewById(R.id.videoView_video);
final Uri path1 = Uri.parse("android.resource://com.ivirtual.promotaxi/"
+R.raw.intro);
final Uri path2 = Uri.parse("android.resource://com.ivirtual.promotaxi/"
+R.raw.intro2);
final Uri path3 = Uri.parse("android.resource://com.ivirtual.promotaxi/"
+R.raw.intro3);
final Uri path4 = Uri.parse("android.resource://com.ivirtual.promotaxi/"
+R.raw.intro4);
videoView.setVideoURI(path1);
videoView.start();
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
siguiente1();
}
private void siguiente1(){
videoView.setVideoURI(path1);
videoView.start();
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
siguiente2();
}
});
}
private void siguiente2() {
videoView.setVideoURI(path2);
videoView.start();
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
siguiente3();
}
});
}
private void siguiente3(){
videoView.setVideoURI(path3);
videoView.start();
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
siguiente4();
}
});
}
private void siguiente4(){
videoView.setVideoURI(path4);
videoView.start();
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
siguiente1();
}
});
}
});
}
}
谢谢和对不起我的英语。