6

我对 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]

但它似乎失败了。

有人有线索吗?

谢谢!

4

2 回答 2

3

看来我需要

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

viewDidAppear我的视图控制器中......

于 2011-01-12T15:48:54.523 回答
1

您是否查看此链接来处理音频中断。您需要设置 AVAudioSessionDelegate 并处理中断。

于 2011-11-18T14:38:37.980 回答