SoFunction
Updated on 2025-04-07

VideoView enables seamless continuous video playback

This video player uses a relatively simple videoview. The basic idea is to use setOnCompletionListener to monitor the video playback. After the video is played, the next video is played. The video source is placed in the Download folder in the SD card. The specific code is as follows:

public class MainActivity extends Activity {
  VideoView videoView;
  static int pos=1; // Static integer variable is used to mark the video played to the next  MediaController mController;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    (savedInstanceState);
    getWindow().setFormat();
    setContentView(.activity_main);
    videoView=(VideoView)findViewById();
    mController=new MediaController(this);

    File video=new File("/mnt/sdcard/Download/video"+pos+".mp4");


    if(())
    {

      (());
    /* (mController);
      (videoView);*/
      ();
      ();
    }

    (new OnCompletionListener() {

      @Override
      public void onCompletion(MediaPlayer mp) {
        // TODO Auto-generated method stub
        pos=pos+1; //Change the video address to the next one here        File video2=new File("/mnt/sdcard/Download/video"+pos+".mp4");
        if(())
        {
        try {

          (());
          /*(mController);
          (videoView);*/
          ();
          ();

        } catch (Exception e) {
          ();

        }
        }
        else
        {(,"Video playback is finished",Toast.LENGTH_SHORT).show();}


      }

    });
  }


}

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.