开发者

MPMoviePlayerController / AVAudioSession in background doesn't restart play after incoming call

I have an issue with MPMoviePlayerController. I use an instance to play an m3u8 audio source:

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;

it is designed to play when the app goes to background, and everything is working OK.

The problem is when it is in the background and I get an incoming call. In that case, the stream pauses,开发者_如何学编程 but doesn't come back after call ends. In fact, the console says

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!

and the app does show the stream as MPMoviePlaybackStatePlaying, but the sound seems to stop. I have tried doing

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

but it seems to fail.

Does anybody have a clue?

thanks!


It seems like I needed to

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

in viewDidAppear of my viewController....


Did you look at this link to handle audio interruptions. You need to setup AVAudioSessionDelegate and handle the interruptions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜