brian
brian

Reputation: 6912

How to get buffering percent of VideoView on Android

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?

Upvotes: 5

Views: 11158

Answers (2)

cV2
cV2

Reputation: 5319

let your activity implement

OnBufferingUpdateListener ...

and then you get:

  @Override
  public void onBufferingUpdate(MediaPlayer mp, int percent) {

  }

:=) good luck

Upvotes: 0

pixelscreen
pixelscreen

Reputation: 1975

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.

Upvotes: 1

Related Questions