我将视频url存储在一个数组中。我只想播放该数组中的所有视频。
我的Java代码是:
public void video_play(){
VideoView vview= (VideoView)findViewById(R.id.vview);
vview.setVideoURI(Uri.parse(prepare.txtLectureFileName[index_value]));
vview.setMediaController(new MediaController(this));
vview.requestFocus();
vview.start();
if(index_val>=no_of_videos){
Toast.makeText(getApplicationContext(), "Videos are finished", Toast.LENGTH_SHORT).show();
}
else{
video_play();
}
}
我还尝试实现了
onCompleteListener
并创建了一个方法onCompletion()
。但没什么用,请帮我…
最佳答案
嘿,试试这个,对我有用:
public void video_play(){
VideoView vview= (VideoView)findViewById(R.id.vview);
vview.setVideoURI(Uri.parse(prepare.txtLectureFileName[index_value]));
vview.setMediaController(new MediaController(this));
vview.requestFocus();
vview.start();
if(index_val>=no_of_videos){
Toast.makeText(getApplicationContext(), "Videos are finished", Toast.LENGTH_SHORT).show();
}
else{
video_play();
}
vview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion (MediaPlayer mp) {
index_value++;
video_play();
}
});
}