Search code examples
androidandroid-mediaplayer

mediaPlayer won't stop even if I finish the activity


I am in a situation where I have an ActivityGroup and inside of which I have an Activity in which I have used MediaPlayer to play an audio file. But when I navigate out of that Activity I am trying to stop the MediaPlayer, but unfortunately I was not able to do it. So I tried finishing my activity when I navigate out of it. I am able to finish the activity but still MediaPlayer doesn't stop at all.

How should I solve this.


Solution

  • MediaPlayer won't stop when you finish your activity, you need to explicitly call mMediaPlayer.stop() in your activity's onPause().