Seamless video Loop with VideoView

前端 未结 8 1979
春和景丽
春和景丽 2021-01-30 12:03

I have the following code to take a video as a raw resource, start the video and loop it but I need the video to loop seamlessly as of now when it comes to an end of the clip an

相关标签:
8条回答
  • 2021-01-30 12:42

    The pause is for the underlying MediaPlayer to refresh its buffers. How long that will take will depend on a number of factors, many of which are outside your control (e.g., speed of CPU, speed of on-board flash storage).

    One you can control is to get your video out of the resource and into the filesystem. Resources are stored in the APK, which is a ZIP file, so extracting the video this way probably takes extra time.

    You may need to switch away from VideoView and use a SurfaceView with two MediaPlayers, alternating between them -- one is playing while the next is preparing, so when the playing one ends you can switch to the new player. I have not tried this, and so I do not know what the ramifications might be. However, I know that this technique is frequently used for audio playback to transition from one clip to another.

    0 讨论(0)
  • 2021-01-30 12:49

    Not sure if this helps years later, but I used

    vv.start();
    vv.setOnCompletionListener ( new MediaPlayer.OnCompletionListener() {
    
     @Override 
      public void onCompletion(MediaPlayer mediaPlayer) {   
        vv.start();
      }
    });
    

    and it has a seamless loop

    0 讨论(0)
  • 2021-01-30 12:49

    Little late, but any reason that you can't use the following?

    MediaPlayer.setLooping(true);
    
    0 讨论(0)
  • 2021-01-30 12:50

    Answer to this is to remove the audio from the video and convert that to a .ogg file which can be looped seamlessly and then use the video without audio to loop round and this works.

    0 讨论(0)
  • 2021-01-30 12:53

    Try this it will work 100%


    VideoView videoView;<---write this in outside of method or else declare it as final variable.

    videoView.setOnPreparedListener(new OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            mp.setLooping(true);
        }
    });
    
    0 讨论(0)
  • 2021-01-30 12:53

    If you are using Kotlin

     videoView.setOnPreparedListener(object : MediaPlayer.OnPreparedListener {
                    override fun onPrepared(mp: MediaPlayer?) {
                        //Start Playback
                        videoView.start()
                        //Loop Video
                        mp!!.isLooping = true;
                        Log.i(TAG, "Video Started");
                    }
                });
    

    Using Arrow Expression short form

    videoView.setOnPreparedListener { mp ->
                //Start Playback
                videoView.start()
                //Loop Video
                mp!!.isLooping = true;
                Log.i(TAG, "Video Started");
            };
    
    0 讨论(0)
提交回复
热议问题