开发者

Stop sound when user push home button

开发者 https://www.devze.com 2023-01-21 02:34 出处:网络
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开发者_运维知识库

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

精彩评论

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