I am using android.media.MediaPlayer
object to play audio files in my app. Everything works fine but when a phone call comes while a song is playing the app does not pause the media player and you can hear the song during the phone call. Please tell me how to pause media player on a phone call and again resume it after call is ended.
Use a PhoneStateListener
to find out when the phone is in use.
When your Activity (or service) is interrupted by the phone call place MediaPlayer#pause()
into Activity#onPause
and code that resumes playing into Activity#onResume
I think the problem may be that the MediaPlayer is executed in its own thread and when your Activity is paused it doesn't mean that MediaPlayer is automatically paused as well
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