后台MPMoviePlayerController / AVAudioSession在来电后不会重启播放

时间:2011-01-12 12:02:47

标签: iphone mpmovieplayercontroller avaudiosession

我遇到了MPMoviePlayerController的问题。我使用实例播放m3u8音频源:

AVAudioSession *audioSession = [AVAudioSession sharedInstance];

NSError *setCategoryError = nil;
[audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
if (setCategoryError) {
}

NSError *activationError = nil;
[audioSession setActive:YES error:&activationError];
if (activationError) { 
}
self.player =
[[MPMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString:url]];
player.view.hidden = YES;
player.shouldAutoplay = YES;
[player release];
[btnContainer addSubview: player.view];
player.useApplicationAudioSession = NO;

它设计为在应用程序进入后台时播放,一切正常。

问题是当它在后台并且我接到来电时。在这种情况下,流暂停,但在呼叫结束后不会返回。事实上,控制台说

2011-01-12 12:02:27.729 RAC1[1571:307] MP _playbackInterruptionDidEndNotification :: NSConcreteNotification 0x155890 {name = AVController_PlaybackInterruptionDidEndNotification; object = <AVController: 0x180d50>; userInfo = {
    "AVController_InterruptionStatusNotificationParameter" = "call.declined";
    "AVController_InterruptorNameNotificationParameter" = Phone;
}}, _state = 6
2011-01-12 12:02:27.730 RAC1[1571:307] MP _playbackInterruptionDidEndNotification :: resuming playback!

并且应用确实将流显示为MPMoviePlaybackStatePlaying,但声音似乎停止了。我试过做

[[AVAudioSession sharedInstance] setActive: YES error: &err]

但似乎失败了。

有人有线索吗?

谢谢!

2 个答案:

答案 0 :(得分:3)

好像我需要

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

在我的viewController的viewDidAppear ....

答案 1 :(得分:1)

您是否看过this link来处理音频中断问题。您需要设置AVAudioSessionDelegate并处理中断。