Play video one after another

天涯浪子 提交于 2019-12-11 05:13:45

问题


I need to play two video one after another(as a pair), the first video is as intro video and the second video is as main video, So what I actually need is that after finishing intro video the main video will start...say intro-1 & main-1, intro-2&main-2, intro-3& main3...so on. the problem that I am getting is that i cnt move to intro video again after completing the main video.Only the main video is played again and again

Here is that code:

      videoView.setVideoPath(introPath);
        videoView.setMediaController(new MediaController(this));
        videoView.requestFocus();
        videoView.start();


    videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

                public void onCompletion(final MediaPlayer mp) {
                        videoView.setVideoPath(mainPath);
                        MediaController mc = new MediaController(DisplayVideo.this);
                        videoView.requestFocus();
                        videoView.start();
                        }
                        } 

any help will really be appreciated Thanks


回答1:


Create a list of the video paths, something like:

List<String> videoPathes = new ArrayList<String>();
videoPathes.add(path1);
videoPathes.add(path2);
// etc..

and some index, for example:

int i = 0;

In the onCompletionListener, set the next path this way:

public void onCompletion(final MediaPlayer mp) {
    i = (i + 1) % videoPathes.size();
    videoView.setVideoPath(videoPathes.get(i));
    // the rest ...
}


来源:https://stackoverflow.com/questions/8238403/play-video-one-after-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!