Skip to content Skip to sidebar Skip to footer

Cant Stop Playing Sound In Other Activity With Mediaplayer In Android

I'm trying to play a background sound in my Android application. I'm using a seperate class as a Soundmanager. And in my first activity, i start the sound and i want it to play t

Solution 1:

Make all of your methods and class variables in SoundManager static (and pass in a Context for the methods that require one).

I would suspect that you are maybe creating a new instance of SoundManager in each of your Activities, which would create multiple instances of SoundManager. Making it statically accessible will mean all Activities are modifying the same variables.

Another note, I don't think you have to have an Activity Context, so try passing in your application's Context via context.getApplicationContext(). This will avoid tying the MediaPlayer object to any specific Activity.

Solution 2:

Just a guess as I don't know how you are sharing your Soundmanager object:

Maybe you create a new instance of your Soundmanager class in every Activity that is supposed to use it. (i.e. there is a new Soundmanager(context) in each of them or at least an additional one in the stopping Activity).

Post a Comment for "Cant Stop Playing Sound In Other Activity With Mediaplayer In Android"