I am writing an iOS application using AudioQueue for recording. I am creating an input queue configured to receive linear PCM, declared this queue, and everything works as expected.
To control interrupts, I implemented the AVAudioSession delegate methods to catch the start and end of an interrupt. The endInterruption method is as follows:
- (void)endInterruptionWithFlags:(NSUInteger)flags; { if (flags == AVAudioSessionInterruptionFlags_ShouldResume && audioQueue != 0) { NSLog(@"Current audio session - category: '%@' mode: '%@'", [[AVAudioSession sharedInstance] category], [[AVAudioSession sharedInstance] mode]); NSError *error = nil; OSStatus errorStatus; if ((errorStatus = AudioSessionSetActive(true)) != noErr) { error = [self errorForAudioSessionServiceWithOSStatus:errorStatus]; NSLog(@"Could not reactivate the audio session: %@", [error localizedDescription]); } else { if ((errorStatus = AudioQueueStart(audioQueue, NULL)) != noErr) { error = [self errorForAudioQueueServiceWithOSStatus:errorStatus]; NSLog(@"Could not restart the audio queue: %@", [error localizedDescription]); } } }
If the application is interrupted when it is in the foreground, everything works correctly. The problem occurs if the interrupt occurs in the background. Activating an audio session will result in an error ! Cat :
The specified audio session category cannot be used to attempt to play audio. For example, you tried to play or record audio with the audio session category set to kAudioSessionCategory_AudioProcessing.
Running a queue without activating a session results in an error: -12985
At this point, the category is set to AVAudioSessionCategoryPlayAndRecord , and the mode is AVAudioSessionModeDefault .
I could not find the documentation for this error message, and I can also restart the input audio queue in the background.
Tobias Kräntzer
source share