开发者

Stop sound when user push home button

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 ho开发者_运维知识库me button?


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 :)


NSString *path = [[NSBundle mainBundle] pathForResource:@"*" ofType:@"mp3"];

If you use * in the place of the mp3 name the music will be stopped.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜