5

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
  • 6,802
  • 29
  • 83
  • 124
  • 1
    `VideoView` does not provide access to its wrapped `MediaPlayer` or a way to set a callback for buffering progress, although it uses both internally. The way I see it, you could either poll the value by repeatedly calling `getBufferPercentage()` (not ideal), or use reflection to get ahold of the `MediaPlayer` instance and register your own listener (also not ideal). – MH. Sep 05 '12 at 19:22
  • I added a Thread that calls getBufferPercentage() every second, but the percentage returned is really weird. It doesn't keep increasing, sometimes it decreases and never goes over a few units %. The same thread works on other the exoplayer, so the calls are right. – ascallonisi Feb 24 '15 at 14:01

2 Answers2

1

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.

pixelscreen
  • 1,945
  • 2
  • 18
  • 40
0

let your activity implement

OnBufferingUpdateListener ...

and then you get:

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

  }

:=) good luck

cV2
  • 5,229
  • 3
  • 43
  • 53
  • I have implemented it in my activity itself, but it does not call back again. – Rakki s Mar 13 '15 at 12:35
  • I have asked as separate question in the following link http://stackoverflow.com/questions/29029597/how-to-startplay-video-once-buffer-reaches-20-in-android-video-view – Rakki s Mar 18 '15 at 08:28
  • okay, sorry currently not into this topic, probably there is some way to setup the buffer for auto playing at some %. good luck. – cV2 Mar 18 '15 at 12:54
  • 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. – Rakki s Mar 18 '15 at 13:05