Skip to content Skip to sidebar Skip to footer

Pause Mediaplayer When Using A Map In Android App

I am building a soundboard with about 40 sounds using a map. (Previous thread) Does anyone know a good way to pause restart Mediaplayer if the app is moved to the background (incom

Solution 1:

I assume you don't want to play all sounds together, so you can declare the mediaplayer object outside the loop and then you don't need to know which file is being played. You can use sound.pause();sound.stop(); or sound.reset(); (depends on the action you want to preform) I suggest you look at the android docs to see how to implement it properly.

If you want to create mediaplayer for each file which I doubt you want, save the mediaplayers in a map / list and pause / reset them in loop during onPause().

Solution 2:

Override Activity.onPause(). This is called whenever your app goes to the background, Home button or back button or incoming call or magic thunderclouds of doom.

Post a Comment for "Pause Mediaplayer When Using A Map In Android App"