StreamingKit
StreamingKit copied to clipboard
Background Audio doesn't resume when user receives a call from iPhone
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?
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.
Never called with AVAudioSessionInterruptionTypeEnded, only with AVAudioSessionInterruptionTypeBegan.