Check out this description of how to handle errors when using MediaPlayer. You should use OnErrorListener
. It will put MediaPlayer into error state (see this state diagram). To exit from this state you need to reset()
the player.
Handling MediaPlayer error when SDCard removed
-
10-06-2023 - |
문제
I want to handle use case when user remove SD Card while Android MediaPlayer is playing song.
I was trying to do it in BroadcastReciever
and listen to ACTION_MEDIA_REMOVED
or other actions related with SD.
I always get errors.
In receiver I was calling player.reset(); to get to idle status. After calling that method my media player stuck in infinite loop with errors printing in logcat.
How can I manage that UC? Can I use OnErrorListener?
I'm using Thread to publish progress of song playback on UI, I'm killing it before resetting player.
해결책
제휴하지 않습니다 StackOverflow