I need to play videos one after the another sequentially.I tried searching in google but dint get any answer.Please help.Its bit urgent.
This is my code
private int[] ids = {R.raw.vid1, R.raw.vid2, R.raw.vid3, R.raw.vid4, R.raw.vid5};
private int index = 1;
private VideoView myVideo1;
OnCreate
//Video Field
myVideo1 = (VideoView) findViewById(R.id.myvideoview);
myVideo1.requestFocus();
myVideo1.setVideoURI(getPath(index));
index++;
myVideo1.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
myVideo1.start();
}
});
myVideo1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
if (index == ids.length) index = 1;
index++;
myVideo1.setVideoURI(getPath(index));
}
});
private Uri getPath(int id) {
return Uri.parse("android.resource://" + getPackageName() + "/raw/vid" + id);
}
We asume that your videos are on raw folder and with name vid1 vid2 etc..