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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With