Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 430
Antonio Avatar asked Jan 12 '11 12:01

Antonio


2 Answers

It seems like I needed to

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

in viewDidAppear of my viewController....

like image 61
Antonio Avatar answered Nov 14 '22 23:11

Antonio


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

like image 22
rydgaze Avatar answered Nov 14 '22 22:11

rydgaze