Android, How to display buffering% from onBufferingUpdate

I have a Media Player service that plays an Internet stream, but I am having problems with the display in my xml percent of buffering, at the moment I'm just showing a message, since all the ways I tried gave me a static long number. Here is the code from my service:

@Override public void onBufferingUpdate(MediaPlayer mp, int percent) { setBufferPosition(percent * getMusicDuration() / 100); myMain.EstadoRadio.setText(" Reproductor \n Buffering... "); } 

as you can tell, EstadoRadio is a text view in my xml that works with myMain activity, where I want to display% stream buffering. Thank you for your help.

EDIT: I saw in most cases where the "percentage" from onBufferingUpdate (MediaPlayer mp, int percent) is used, something like this:

 myMain.EstadoRadio.setText(" Reproductor \n" + percent + "%"); 

but in my case the percentage is always -2147483648, I don’t know why, or why it doesn’t change or update, here is a little from my cat log:

 05-17 13:34:37.005: V/MediaPlayer(25382): message received msg=3, ext1=-2147483648, ext2=0 05-17 13:34:37.005: V/MediaPlayer(25382): buffering -2147483648 05-17 13:34:37.005: V/MediaPlayer(25382): callback application 05-17 13:34:37.005: V/MediaPlayer(25382): getDuration 05-17 13:34:37.015: V/MediaPlayer(25382): back from callback 05-17 13:34:38.016: V/MediaPlayer(25382): message received msg=3, ext1=-2147483648, ext2=0 05-17 13:34:38.016: V/MediaPlayer(25382): buffering -2147483648 05-17 13:34:38.016: V/MediaPlayer(25382): callback application 05-17 13:34:38.016: V/MediaPlayer(25382): getDuration 05-17 13:34:38.016: V/MediaPlayer(25382): back from callback 
+6
source share
1 answer

The number you see is the minimum value of the signed 32-bit int. I would suggest and say that Android cannot return a percentage and actually gives you garbage data.

I would replace your internet stream with a remote mp3 address to make sure that buffering returns the real value (as this will confirm that the rest of your code is not at fault.)

EDIT: Android documentation regarding OnBufferingUpdateListener explains an example of using progressive HTTP downloads rather than an endless internet stream.

I do not believe that the ability to display the percentage of buffering is available using the built-in listeners in Android. Without cracking the Android source code to find out at what point the MediaPlayer class decides to start playing your stream (and even if it provides a callback), I doubt this issue will be resolved.

I would, however, be interested in a solution / workaround if someone can provide it.

http://en.wikipedia.org/wiki/Integer_(computer_science )

http://developer.android.com/reference/android/media/MediaPlayer.OnBufferingUpdateListener.html

+3
source

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


All Articles