Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, How to display the buffering % from onBufferingUpdate

I have a Media player service that plays a internet stream, but I'm having problems on how to display in my xml the buffering percentage, at the moment I'm just displaying a message since all the ways I have try it gave me a static long number. Here is the code from my player 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 is working from myMain activity where I want to display the buffering % of the stream. Thanks for your help.

EDIT: I have seen inmost cases where 'percent' from the onBufferingUpdate(MediaPlayer mp, int percent) is used, something like this:

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

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

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
like image 771
zvzej Avatar asked May 17 '12 18:05

zvzej


1 Answers

The number you are seeing is the min value of a signed 32 bit int. I would take a guess and say that Android is unable to return a percentage and is in fact giving you trash data.

I'd replace your internet stream with a remote mp3 URL to see if buffering gets a real value back (As this would confirm the rest of your code is not to blame.)

EDIT: The Android documentation regarding the OnBufferingUpdateListener explains the use case for a progressive http download, not an endless internet stream.

I do not believe that the ability to display a buffering percentage is available using the inbuilt listeners within Android. Without cracking open the Android source to find at what point the MediaPlayer class decides to start playing your stream (and if they even provide a callback), I doubt this question will be resolved.

I would however be interested in a solution/workaround if anybody can provide one.

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

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

like image 54
stevokk Avatar answered Sep 27 '22 19:09

stevokk