Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 through 2 other activitys. And in my third class i want it to stop and another sound should play. But im having a problem stopping that sound and don't know why. I guess it has something to do with that im using the class Context in my Soundmanager class.

Does anyone know how to make the sound stop? I'll link my Soundmanager class becuase that is the only one that is relevant i guess. Im pretty new to programming, so please be gentle.

Soundmanager class http://codepad.org/KJi6DZN6

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
161 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...