سؤال

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