Skip to content

Instantly share code, notes, and snippets.

@mattbriancon
Created April 12, 2011 19:05
Show Gist options
  • Save mattbriancon/916157 to your computer and use it in GitHub Desktop.
Save mattbriancon/916157 to your computer and use it in GitHub Desktop.
Spin up a thread to check whether MediaPlayer is buffering smoothly
boolean hasUpdated = false;
boolean doneBuffering = false;
long bufferTimeout = 500;
// put this somewhere smart
new Thread(new Runnable() {
public void run() {
while(!doneBuffering) {
Thread.sleep(bufferTimeout);
if(hasUpdated)
// buffering smoothly
hasUpdated = false;
else
// buffering might have paused...
}
}
}).start();
private BufferListener implements MediaPlayer.OnBufferingUpdateListener {
public onBufferingUpdate(MediaPlayer mp, int percent) {
hasUpdated = true;
if(percent == 100)
doneBuffering = true;
progressBar.setSecondaryProgress(percent); // or whatever
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment