Find out what MediaPlayer is playing and stop it onPause or onStop?

Does anyone know a good way to find out what is currently playing MediaPlayerand stop / pause it by overriding onStop()or onPause()? Or just stop MediaPlayerwhen the application is in the background? I have a lot of sounds and I donโ€™t know what will play at any moment. Sorry, still studying here.

+5
source share
3 answers

You can check if MediaPlayer is null and stop it if it is not. You can do this for all of your MediaPlayers in the Stop button or onBackPressed ()

if (myPlayer != null){
    myPlayer.stop();
}
0
source

, .

@Override
protected void onStop() {
    super.onStop();
    mediaPlayer.stop();
    mediaPlayer.release();
}
0

You can stopandrelease mediaPlayer

@Override
protected void onStop() {
    mediaPlayer.stop();
    mediaPlayer.release();
}
0
source

All Articles