1

谁能教我如何让视频一个接一个地播放

我需要完整的代码

我有 4 个视频

视频1、视频2、视频3、视频4

我希望先播放 Video1,然后播放 Video2,然后播放 Video3,然后播放 Video4

String path="android.resource://" + getPackageName() +"/" + R.raw.Video1;
videoView1.setVideoURI(Uri.parse(path));
videoView1.start();
4

4 回答 4

0

假设您有一个 Videoview,例如,您可以将视频的路径放入一个数组中,并像这样检测播放的结束:

videoView.setOnCompletionListener(new OnCompletionListener() {
    @Override
    public void onCompletion(MediaPlayer mp) {
        //start next video here
        //for example, set video path to next array item            
    }       
});
于 2013-08-07T03:14:40.083 回答
0

也许你应该创建一个新VideoView的来播放下一个视频OnCompletionListener,并删除旧的 VideoView,添加新的 VideoView。

这个对我有用。

于 2015-07-09T05:46:22.130 回答
0

Short & Simple

Let's say you have four videos in array list

ArrayList<String> urlList = new ArrayList<>();

Create one counter variable to manage current video playing.

int video_counter = 0;

Now following code make your work easy to play dynamic range of video to play in loop (like one after another).

VideoView vv_video = findViewById(R.id.vv_video);

vv_video.setVideoURI(Uri.parse(urlList.get(counter_video_loop)));

vv_video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

                    @Override
                    public void onPrepared(MediaPlayer mp) {
                        vv_video.start();
                    }
                });

vv_video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                    @Override
                    public void onCompletion(MediaPlayer mp) {
                        if ((video_counter + 1) <= urlList.size()) {
                            video_counter++;
                            vv_video.setVideoURI(Uri.parse(urlList.get(video_counter + 1)));
                            vv_video.start();
                        } 
                    }
                });
于 2019-04-12T08:19:36.160 回答
0

使用 exoPlayer 连接多视频

于 2019-01-18T06:01:26.990 回答