Possible Duplicate:
When I exit an application the sound runs on the background
When i click the home button or back button, the audio/sound still running, the source of the audio is swf(flash) so how can i fix it?
Possible Duplicate:
When I exit an application the sound runs on the background
When i click the home button or back button, the audio/sound still running, the source of the audio is swf(flash) so how can i fix it?
You have to override the onPause method and stop the audio there.
player.pause();
You should pause and release player in onPause
or onStop
and init in onStart
or onResume
. Android Developer site has training about this. You should add this code in your activity
@Override
public void onPause() {
super.onPause(); // Always call the superclass method first
// Release the mPlayer because we don't need it when paused
// and other activities might need to use it.
// You change this part to your implement. Stop your player
if (mPlayer != null) {
mPlayer .release()
mPlayer = null;
}
//
}
Init again in onResume
@Override
public void onResume() {
super.onResume(); // Always call the superclass method first
// Get the mPlayer instance as the activity achieves full user focus
if (mPlayer == null) {
initializePlayer (); // Local method to handle mPlayer init
}
}