1

我需要一个接一个地播放视频。我尝试在谷歌搜索,但没有得到任何答案。请帮忙。有点紧急。

这是我的代码

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

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

4

2 回答 2

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();
        }
    };
于 2012-07-19T12:16:50.407 回答
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;

创建时

//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);
}

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

于 2016-04-26T07:23:34.740 回答