AVAudioPlayer play not working after incoming FaceTime interruption

I have an app that plays music using AVAudioPlayer. When the app is in the background and there is an incoming FaceTime call, I receive the AVAudioSessionInterruptionNotification to pause the player. When I then end the FaceTime call, I get the AVAudioSessionInterruptionNotification again. However, when I call 'play' on the AVAudioPlayer, I don't hear any audio starting. When the same happens on a phone call, or an *outgoing* FaceTime call the audio player resumes playing perfectly fine. I've added my code below. Does anybody know what I'm doing wrong, or whether this is a bug? The same codes works fine on iOS 8.


// Setup Audio Session
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&error];
[audioSession setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&error];   

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interruption:) name:AVAudioSessionInterruptionNotification object:nil];

// Setup Audio Player
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:self.songURL error:nil];
if ([self.audioPlayer prepareToPlay]) {
    [self.audioPlayer play];
}


...


- (void)interruption:(NSNotification *)notification {
    NSDictionary *userInfo = notification.userInfo;
    if ([[userInfo objectForKey:AVAudioSessionInterruptionTypeKey] integerValue] == AVAudioSessionInterruptionTypeBegan) {
        NSLog(@"Audio session was interrupted");
        [self.audioPlayer pause];
    } else if ([[userInfo objectForKey:AVAudioSessionInterruptionTypeKey] integerValue] == AVAudioSessionInterruptionTypeEnded) {
        NSLog(@"Audio interruption ended");
        if ([self.audioPlayer prepareToPlay]) {
            NSLog(@"Will resume playing audio");
            [self.audioPlayer play];
        } else {
            NSLog(@"Failed to prepare to play");
        }
    }
}

Replies

I noticed something similar and the issue is that when you receive and hang up a FaceTime call the AVAudioSessionInterruptionTypeEnded type is never called. Only the AVAudioSessionInterruptionTypeBegan. I'm assuming this is a bug.

Hi, did you manage to get a solution for this? I'm stuck with the same in my swift app.

I see the AVAudioSessionInterruptionType .Ended sent correctly but when I call my player to play nothing comes out (works fine when in foreground)

Thanks

EDIT - ignore that, fixed by adding MixWithOthers option, with you already have