I'm writing an audio player using MediaPlayer that allows the user to skip the actual tune. A skip request might occur at any time, including between a call to MediaPlayer.prepareAsync and the upcoming onPrepared callback. The doc says:
It is important to note that the Preparing state is a transient state, and the behavior of calling any method with side effect while a MediaPlayer object is in the Preparing state is undefined.
Does that include calls to reset, or even to release? Because if it so, then I would either have to wait for the onPrepared callback to reuse the MediaPlayer or allocate a brand new MediaPlayer if I don't want to wait and release the obsolete one on the onPrepared callback, right?
I also built a stream music player and struggled with the preparing state. The worse part of it was that there were some streams where prepare() hung forever downloading (buffering) data without ever calling onBufferUpdate. Calling release did nothing. So, the way I did it was calling reset() on the stuck MediaPlayer from anotherthread after 15 seconds despite the recommendations in the docs. This caused it to throw an exception and brought it to error state. After catching the exception I called release(). This seems to have solved the problem. I hope this will be useful to someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With