I'm doing my first game in android, it's almost done, but I have a problem with the music, the music starts and ends when you start the game or die, but if you press the home button or the back button it doesn't ever stop
I have tried looking here for solution, but nothing works well with my code
This is the SoundBank class, playBackground it's called when the game starts, stopBackground when you die
public class SoundBank {
Context context;
MediaPlayer background, hit;
int mute;
GameOver gameOver = new GameOver();
public SoundBank(Context context){
this.context = context;
hit = MediaPlayer.create(context,R.raw.sfx_hit);
background = MediaPlayer.create(context,R.raw.background);
mute = gameOver.getMute();
}
public void playHit(){
if(mute != 1){
hit.start();
}
}
public void playBackground(){
if(background != null){
background.start();
background.setLooping(true);
}
}
public void stopBackground(){
if(background != null){
background.stop();
}
}
}
I expect the music to end when I press home button or back button