Search code examples
androidmedia-playerbuffering

Android - How to tell when MediaPlayer is buffering


I've got to be missing something obvious here, but I can't seem to find anything to allow me to determine when MediaPlayer is buffering audio. I'm streaming internet audio and I want to display a buffering indicator, but nothing I've tried allows me to know when MediaPlayer interrupts the audio to buffer, so I can't properly display a buffering indicator. Any clues?


Solution

  • @Daniel, per your comment on @JRL's answer, you could probably get this working by spinning up a thread and waiting for a timeout.

    Something like DetectBufferTimeout.java (untested) would do nicely.

    I do, however, agree that spinning up this separate thread is a bit of a hack. Perhaps OnBufferingUpdateListener could make a guarantee as to how often it calls onBufferingUpdate() regardless of whether a change in the buffering progress has occurred so we can detect if we're getting the same value over and over.