How to get buffering percent of VideoView on Android

10,641

Implement this method for your VideoView:

public abstract void onBufferingUpdate (MediaPlayer mp, int percent)

mp is the MediaPlayer the update pertains to percent is the percentage (0-100) of the content that has been buffered or played thus far.

Source

You can add a progressbar before u start loading the Video, and then keep updating it inside this method. And once the buffering is complete (in onPreparedListener), just dismiss the progressbar.

Share:
10,641
brian
Author by

brian

Updated on June 14, 2022

Comments

  • brian
    brian almost 2 years

    My code as below:

    Uri uri = Uri.parse(URL);
    video.setVideoURI(uri);
    video.start();
    

    I use VideoView to play a stream video.
    The video is a VideoView.
    And I want to get the buffering percent like setOnBufferingUpdateListener in MediaPlayer.

    MediaPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
        @Override
        public void onBufferingUpdate(MediaPlayer mp, int percent) {
            //buffering is percent
        }
    });
    

    How can I do it?

  • brian
    brian over 11 years
    But I don't need progressbar, I only need the percent number.
  • pilcrowpipe
    pilcrowpipe over 11 years
    This is incorrect. Implementing onBufferingUpdate in a subclassed VideoView does nothing.
  • Rakki s
    Rakki s about 9 years
    I have implemented it in my activity itself, but it does not call back again.
  • Rakki s
    Rakki s about 9 years
    I have asked as separate question in the following link stackoverflow.com/questions/29029597/…
  • cV2
    cV2 about 9 years
    okay, sorry currently not into this topic, probably there is some way to setup the buffer for auto playing at some %. good luck.
  • Rakki s
    Rakki s about 9 years
    No actually i have added the call back function for the buffer listener in that code but it's not called that's my issues ... i know the way to start play after some percentage.