如何依次播放视频?

时间:2012-07-19 12:02:04

标签: android video

我需要按顺序依次播放视频。我尝试在谷歌搜索但是得到任何答案。请帮忙。有点紧急。

这是我的代码

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

        }
    }); 

}

}

我需要循环播放视频,以便他们一个接一个地播放

2 个答案:

答案 0 :(得分:3)

试试这个:

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

设置功能:

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

将onCompletionListener实现为:

OnCompletionListener completionListener=new OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {
            mp.stop();
            setup();
        }
    };

答案 1 :(得分: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);
}

我们假设您的视频位于原始文件夹中,名称为vid1 vid2等。