I added a notification to listen for interrupts from others:
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(audioInterruption:)
name:AVAudioSessionInterruptionNotification
object:nil];
- (void)audioInterruption:(NSNotification *)audioInterruptNotification{
NSLog(@"interrupted!");
NSDictionary *interruptionDictionary = [audioInterruptNotification userInfo];
NSNumber *interruptionType = (NSNumber *)[interruptionDictionary valueForKey:AVAudioSessionInterruptionTypeKey];
if ([interruptionType intValue] == AVAudioSessionInterruptionTypeBegan) {
NSLog(@"Interruption started");
} else if ([interruptionType intValue] == AVAudioSessionInterruptionTypeEnded){
NSLog(@"Interruption ended");
BOOL success = [[AVAudioSession sharedInstance] setActive:YES withOptions:NO error:nil];
if (!success) {
NSLog(@"avaudio session set active failed");
}
} else {
NSLog(@"Something else happened");
}
}
When an interruption occurs, the notification is fine, but it is not
[[AVAudioSession sharedInstance] setActive:YES withOptions:NO error:nil];. And why did this happen and how could I resume the game after the breaks (I used AudioQueue to play or record instead of AVAudioPlayer)?
source
share