【发布时间】:2011-12-26 22:12:14
【问题描述】:
所以我正在编写一个在 AVPlayer 中播放音乐的应用程序,并且我想在接到电话或其他事情结束在后台播放的音乐时捕捉事件。
- (void)applicationWillResignActive:(UIApplication *)application
这是在应用程序中断时捕获的正确方法,但是当用户完成电话通话时,是否有另一种方法可以让我在通话结束时从中断的地方恢复播放器,并且应用程序再次设置为活动状态?
提前感谢您的帮助。
编辑:答案
- (void) beginInterruption {
if (playing) {
playing = NO;
interruptedWhilePlaying = YES;
[self updateUserInterface];
}
}
NSError *activationError = nil;
- (void) endInterruption {
if (interruptedWhilePlaying) {
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];
[player play];
playing = YES;
interruptedWhilePlaying = NO;
[self updateUserInterface];
}
}
这就是答案,只要你实现了 AVAudioSession 委托
【问题讨论】:
标签: iphone objective-c ios