VideoView Play several videos

1

Hello friends, I have a small problem that I do not know how to perform, well I'm trying to play some videos in mp4 which I need when I start the first one and I'll start a second video I really do not know how to do it.

public class Videos extends AppCompatActivity {
    VideoView videoView;
    Button siguiente;
    int mas=0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_videos);
        videoView = (VideoView) findViewById(R.id.videoView);
        siguiente=(Button)findViewById(R.id.siguiente);

        siguiente.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              if (mas==0)
              {
                  mas=1;
              }else
                if (mas==1)
                {
                    Uri path = Uri.parse("android.resource://com.example.admin.relojfinal/" + R.raw.video1);
                    MediaController mc = new MediaController(Videos.this);
                    videoView.setMediaController(mc);
                    videoView.setVideoURI(path);
                    videoView.start();
                    mc.setVisibility(View.GONE);
                    mas=2;
                }else
                    if (mas==2)
                    {
                        Uri path = Uri.parse("android.resource://com.example.admin.relojfinal/" + R.raw.video2);
                        MediaController mc = new MediaController(Videos.this);
                        videoView.setMediaController(mc);
                        videoView.setVideoURI(path);
                        videoView.start();
                        mc.setVisibility(View.GONE);
                    }
            }
        });

    }
}
    
asked by GOMEZ MUÑOZ BRAYAN 02.11.2016 в 16:39
source

1 answer

1

To do this, you have the listener OnCompletionListener to detect when the reproduction of a file ends, based on this you can reproduce the following and so on:

  videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
                            //Termina la reproducción, reproduce el siguiente video.      
            startNextVideo();

            }
        });

The startNextVideo() method could define the Uri of the next video in the list and start playback.

I'll add an example of what I'm saying, a response made by @BlueSword :

link

videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
            startOtherVideo();
        }
});

Method that would be called to complete the reproduction of mp4.

private void startOtherVideo(){
  //Asegura detener reproducción.
  videoView.stopPlayback();
  //Define Uri del siguiente video.
  videoUri = Uri.parse("<PATH SIGUIENTE VIDEO>");
  videoView.setVideoURI(videoUri);
  //Inicia reproducción nuevamente.
  videoView.start(); 
}
    
answered by 02.11.2016 / 19:59
source