views:

25

answers:

1

I play a sound in viewDidLoad now when user push home button sound paused.when user run app again sound play from place that paused before.how can i stop it(no pause) when user push home button?

A: 

Have a look into the application delegate methods:

- (void)applicationDidEnterBackground:(UIApplication *)application

- (void)applicationWillResignActive:(UIApplication *)application

You may place code there that gets run, when your app is closed. Try keeping a pointer to you AVAudioplayer around and "stop" its currently playing content if necessary. Be sure to restart it when the user comes back!

The documentation on the "UIApplicationDelegate Protocol Reference" helps :)

Bersaelor
imagine that i have an app with two view and this player is in second view how can i call player from applicationDidEnterBackground for stop it ?
SajjadZare
Either put the pointer to the player in your application delegate or make it a property of the view and somehow get a pointer to your view from the app-delegate. I usually have an application-wide sound-playing class that is somehow connected to the App-Delegate. Remember you can get a pointer to your delegate from anywhere in your code by calling [UIApplication sharedApplication].delegate.
Bersaelor