How to stop the music playing in background in android
-
28-10-2019 - |
Question
i tried to stream an audio from url and its working fine. The url is playing on background also when i quit the application. But i cant able to stop it when i enter my app again how could i stop. Help is appreciated.
Solution
Put this in your main activity (or wherever you placed your player):
protected void onPause() {
super.onPause();
// Put your media player object here
mp.pause();
}
That should stop your music whenever you leave your activity.
OTHER TIPS
In your onBackPressed method write mp.stop() and then mp=null where mp is your mediaplayer instance...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow