문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top