MPMoviePlayerController / AVAudioSession in the background does not restart playback after an incoming call

I have a problem with MPMoviePlayerController. I am using an instance to play the m3u8 sound 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 application goes to the background and everything works fine.

The problem is that it is in the background and I am receiving an incoming call. In this case, the thread pauses, but does not return after the call ends. Actually 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 application shows the stream as MPMoviePlaybackStatePlaying , but the sound seems to stop. I tried to do

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

but it does not seem to work.

Does anyone have a key?

thanks!

+6
iphone mpmovieplayercontroller avaudiosession
source share
2 answers

I think I need

 [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 

in viewDidAppear my viewController ....

+3
source share

You have looked at this link to handle audio interruptions. You need to configure AVAudioSessionDelegate and handle interrupts.

+1
source share

All Articles