While listening to a 1 hour mp3 stream, if a user loses connections (or changes from WIFI to 3G and the connection “Drops” for a second) we’ve noticed that MediaPlayer continues to play the content it has buffered. Once it runs out of buffered content, if it’s not completed to the end of the file, I would have assumed it fires an Error event, but instead it changes state to PLAYBACK_COMPLETE. How can we figure out if the end of playback was due to an error in the connection (loss of connection) or actual playback completion? The only thing I’ve been able to come up with is to check currentPostion vs totalDuration when MediaPlayer changes state to PLAYBACK_COMPLETE. Is there a better way?
Share
If it did not fire an
onError()event, you can try registering anOnBufferingUpdateListenerand check if the buffering percentage reaches 100%. If the connection is lost, on playback completion the percentage would be less than 100%.