Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interrupt android MediaPlayer.prepareAsync()?

I use Android MediaPlayer for streaming audio playback. But some times record preparing stage takes too long. So I would like to give user ability to interrupt preparing and start another. How can I do this?

Thanks in advance.

Michael

like image 257
Lampapos Avatar asked Mar 20 '26 17:03

Lampapos


1 Answers

As can be seen in the list of valid and invalid states, the Preparing state is never mentioned, not in the invalid states and, much more importantly, not in the valid states. While this is a bit confusing, you are better of ignoring the list of invalid states and just not calling a method if the current state is not listed as valid.

So, the only methods that are valid for you to call are those that are valid in any state. Thus, the only way to achieve your goal without using two alternating MediaPlayers is to release() the MediaPlayer and create a new one.

like image 109
Jelle Fresen Avatar answered Mar 23 '26 05:03

Jelle Fresen