Reputation: 159
I have iOS app that handles audiosession interrupts with:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AudioInterrupt:)
name:AVAudioSessionInterruptionNotification
object: NULL];
and in AudioInterrupt:
- (void)AudioInterrupt:(NSNotification*)notification
{
NSDictionary *interuptionDict = notification.userInfo;
// get the AVAudioSessionInterruptionTypeKey enum from the dictionary
NSInteger interuptionType = [[interuptionDict valueForKey:AVAudioSessionInterruptionTypeKey] integerValue];
NSNumber* seccondReason = [[notification userInfo] objectForKey:@"AVAudioSessionInterruptionOptionKey"] ;
// decide what to do based on interruption type here...
switch (interuptionType) {
case AVAudioSessionInterruptionTypeBegan:
[[[self pureAudioHandler] audioController] setActive: NO];
NSLog(@"Interruption started");
break;
case AVAudioSessionInterruptionTypeEnded:
NSLog(@"Interruption ended");
break;
}
switch ([seccondReason integerValue]) {
case AVAudioSessionInterruptionOptionShouldResume:
NSLog(@"Resume Audio");
[[[self pureAudioHandler] audioController] configurePlaybackWithSampleRate:44100 numberChannels:2 inputEnabled:NO mixingEnabled:YES];
[[[self pureAudioHandler] audioController] setActive: YES];
break;
default:
break;
}
}
This works fine with alarms and Siri. However if i have no internet connection and i press home button i get "Siri not available...". AVAudioSessionInterruptionTypeBegan is triggered. Press homebutton twice to get back into app and nor AVAudioSessionInterruptionTypeEnded or AVAudioSessionInterruptionOptionShouldResume is fired. Any workarounds?
iPad mini retina with 7.0.3
Upvotes: 1
Views: 1837
Reputation: 159
Lot of experimenting showed that interrupts aren't fired all times as they should. Sometimes missing InterruptionTypeBegan when entering Siri, and all this happens quite randomly on current testcase (Unity3D & Kalimba(libpd)).
Instead used applicationWillResignActive for killing audio and applicationDidBecomeActive to start it again, as these are working 100% of the time.
Interesting fact is that when entering back from Siri (no wifi, so "Siri not available..." appears), it changes samplerate back to half of machines native samplerate (24000 on ipad mini) after some time.
Upvotes: 2