1

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

public class PlayThisVideo extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
        mediaController=new MediaController(PlayThisVideo.this);
        Uri videoURI=Uri.parse("android.resource://com.VideoAppProject/"+R.raw.baa_baaa_blacksheep);
        videoview.setMediaController(mediaController);
        videoview.setVideoURI(videoURI);
        videoview.requestFocus();
        videoview.start();
        
        videoview.setOnCompletionListener(new OnCompletionListener() {
            
            public void onCompletion(MediaPlayer mp) {
                // TODO Auto-generated method stub

                Uri videoURI=Uri.parse("android.resource://com.VideoAppProject/"+R.raw.ding_dong_bell);
                videoview.setMediaController(mediaController);
                videoview.setVideoURI(videoURI);
                videoview.requestFocus();
                videoview.start(); 
                
            }
        }); 
    }
}

I need to loop videos so that they play one after another

Mahesh Babariya
  • 4,560
  • 6
  • 39
  • 54
Sujay Karanj
  • 81
  • 1
  • 3
  • 7

2 Answers2

3

Try this:

videoView = (VideoView) findViewById(R.id.v);
setup();
videoView.setOnCompletionListener(completionListener);

setup Function:

public void setup() {
        Uri uri = Uri.parse("android.resource://" + getPackageName() + "/"
                + R.raw.test);
        videoView.setVideoURI(uri);
        videoView.start();
    }

implement onCompletionListener as:

OnCompletionListener completionListener=new OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {
            mp.stop();
            setup();
        }
    };
AkashG
  • 7,868
  • 3
  • 28
  • 43
  • make array of id's of the video and pass the array – AkashG Jul 19 '12 at 12:30
  • I have a video that plays on a tablet but does not play on a android device.What should be done to make it play on a device?Is there any resolution that has to be changed? – Sujay Karanj Jul 23 '12 at 11:39
0
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..

Aldo
  • 55
  • 2
  • 11