Hi!
I have an issue with Audio interruption working properly. Everything works very well both on device or simulator while in debug mode. However Audio does not resume playing after incomming call when device is disconnected from Xcode... Please advise me why could this be happening? What am I doing not right?
Here is my code which is inside of AppDelegate:
-(void)audioInterruption:(NSNotification*)notification
{
NSNumber *interruptionType = [[notification userInfo] objectForKey:AVAudioSessionInterruptionTypeKey];
NSNumber *interruptionOption = [[notification userInfo] objectForKey:AVAudioSessionInterruptionOptionKey];
switch (interruptionType.unsignedIntegerValue) {
case AVAudioSessionInterruptionTypeBegan:{
dispatch_async(dispatch_get_main_queue(), ^{
BOOL isPlayingWithOthers = [[AVAudioSession sharedInstance] isOtherAudioPlaying];
if(isPlayingWithOthers || [self.audioPlayer rate]>0)
{
[self.audioPlayer pause];
self.audioInterrupted = YES;
}
});
break;
}
case AVAudioSessionInterruptionTypeEnded:{
if (interruptionOption.unsignedIntegerValue == AVAudioSessionInterruptionOptionShouldResume) {
dispatch_async(dispatch_get_main_queue(), ^{
if(self.audioInterrupted)
{
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self.audioPlayer play];
self.audioInterrupted = NO;
}
});
}
break;
}
default:
break;
}
}