-1

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?

Community
  • 1
  • 1
Gil Ralph
  • 21
  • 1
  • 5
  • Did you try to stop whatever it is you want to stop in the `onPause()`? – iTurki Sep 29 '12 at 13:58
  • how i use onpause()? and nope i heard about that... but how i use it? if you can give me the script its will be great! the flash name is: game.swf – Gil Ralph Sep 29 '12 at 14:03

2 Answers2

1

You have to override the onPause method and stop the audio there.

player.pause();
Araw
  • 2,410
  • 3
  • 29
  • 57
  • X2: how i use onpause()? and nope i heard about that... but how i use it? if you can give me the script its will be great! the flash name is: game.swf – Gil Ralph Sep 29 '12 at 14:03
  • @GilRalph Check Yul's answer :) – Araw Sep 29 '12 at 14:05
  • yep thanks! but where i need to put this 2 scripts? and i need to edit this 2 codes or just copy and past? – Gil Ralph Sep 29 '12 at 14:17
  • It's called methods, not scripts ;) Unless they are overriden the application will have the default behaviour when the application is put into background (onPause is called when that happens). When the application is resumed onResume is called. So in order to make your own application behaviour on a customized way when this actions is called you paste in the override public onPause() and override public onResume() methods in the same class as your activity (I guess you only have one activity). Hence, in the same file where it stands "extends Activity". Did this make things anymore clear? – Araw Sep 29 '12 at 14:32
1

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
    }
}
Trung Nguyen
  • 7,442
  • 2
  • 45
  • 87