How to get VideoView buffering percentage on Android

My code is as below:

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

I use VideoView to play streaming video.
Video - VideoView.
And I want to get the percentage of buffering, for example, setOnBufferingUpdateListener in MediaPlayer.

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

How can i do this?

+4
source share
2 answers

Implement this method for your VideoView:

 public abstract void onBufferingUpdate (MediaPlayer mp, int percent) 

mp is MediaPlayer, the update of which relates to a percentage - this is the percentage (0-100) of content that has been buffered or played so far.

A source

You can add a progress indicator before the video starts downloading, and then continue updating it inside this method. And once buffering is complete (in onPreparedListener), just release the progressbar.

+1
source

activate activity

OnBufferingUpdateListener ...

and then you get:

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

: =) luck

0
source

Source: https://habr.com/ru/post/1432444/


All Articles