StreamingKit icon indicating copy to clipboard operation
StreamingKit copied to clipboard

Background Audio doesn't resume when user receives a call from iPhone

Open tobitech opened this issue 9 years ago • 2 comments

I'm using the STKAudioPlayer, when app is minimised it continues to play in background but when the phone receives a call, the background audio stops and doesn't resume. How do I fix this?

tobitech avatar Mar 17 '16 07:03 tobitech

Subscribe to AVAudioSessionInterruption notification

And do the following in the callback

   NSDictionary *interuptionDict = notification.userInfo;
    NSInteger interuptionType = [[interuptionDict valueForKey:AVAudioSessionInterruptionTypeKey] integerValue];

    switch (interuptionType) {
        case AVAudioSessionInterruptionTypeBegan:
            if (![[MediaPlayer shared]  isPausedState]){
                [[MediaPlayer shared]  pause];
                hasAudioInterruptStarted = YES;

            }
            NSLog(@"Interruption started");
            break;
        case AVAudioSessionInterruptionTypeEnded:
            if ([MediaPlayer shared] isPausedState] && hasAudioInterruptStarted){
                [[MediaPlayer shared] resume];
                hasAudioInterruptStarted = NO;
            }
            NSLog(@"Interruption ended");
            break;
    }

Where MediaPlayer is your StreamingKit abstraction.

patrickjquinn avatar Mar 28 '16 21:03 patrickjquinn

Never called with AVAudioSessionInterruptionTypeEnded, only with AVAudioSessionInterruptionTypeBegan.

iDevelopper avatar May 10 '17 06:05 iDevelopper