VideoView onResume loses buffered portion of the video

后端 未结 10 502
北恋
北恋 2020-12-01 02:56

I am having an Activity in which there is

  1. VideoView -- Streams a video from a webserver.

  2. Button -- Takes the user to the next activit

相关标签:
10条回答
  • 2020-12-01 03:44

    The problem with videoView.resume() in onResume() can be seen here: VideoView.resume(). VideoView.resume() calls openVideo() which first releases any previous MediaPlayer instances and then starts a new one. I cannot see an easy way out of this.

    I see two possibilities:

    • Write your own VideoView which retains the MediaPlayer instance for as long as you want. Or just take the source and modify to your liking, it's open source (check the license, though).
    • Create a network proxy in your app which stands between the VideoView and the web server. You point your proxy to the web server and the VideoView to the proxy. The proxy starts downloading the data, saves it continuously for later use and passes it to the listening MediaPlayer (which was started by the VideoView). When the MediaPlayer disconnects, you keep the already downloaded data, so that when the MediaPlayer restarts the playback, you don't have to download it again.

    Have fun! :)

    0 讨论(0)
  • 2020-12-01 03:46

    As the buffer is lost when the video view goes to the background(change in visibility), you should try blocking this behavior by overriding the onWindowVisibilityChanged method of VideoView. Call super only if the video view is becoming visible. May have side-effects.

    public class VideoTest extends VideoView {
    
        public VideoTest(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        protected void onWindowVisibilityChanged(int visibility) {
            if (visibility == View.VISIBLE) { 
                super.onWindowVisibilityChanged(visibility);
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-01 03:46
    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        videoView.pause();
        super.onPause();
    }
    
    @Override
    protected void onRestart() {
        // TODO Auto-generated method stub
        videoView.resume();
        super.onPause();
    }
    

    try by adding above twomethods in your activity.

    0 讨论(0)
  • 2020-12-01 03:47

    In onPause() function, instead of

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        videoView.suspend();
    }
    

    try

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        videoView.pause();
    }
    
    0 讨论(0)
提交回复
热议问题