Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 765
brian Avatar asked Nov 12 '22 23:11

brian


1 Answers

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.

like image 146
pixelscreen Avatar answered Dec 24 '22 22:12

pixelscreen