Created
April 12, 2011 19:05
-
-
Save mattbriancon/916157 to your computer and use it in GitHub Desktop.
Spin up a thread to check whether MediaPlayer is buffering smoothly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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