Handling App Interruptions - AudioUnit fails to restart
Handling App Interruptions - AudioUnit fails to restart
- Subject: Handling App Interruptions - AudioUnit fails to restart
- From: Joe White <email@hidden>
- Date: Wed, 03 Apr 2013 17:11:22 +0100
Hi all,
I'm currently stuck on an issue where the audio unit is failing to restart after an interruption to the app.
I'm building on an iPod Touch 5 running iOS 6.1.3 and noticed that libpd's way of using the delegate method to handle interruptions is deprecated (endInterruptionWithFlags methods were being inconsistently called).
So I've set up a notification for AVAudioSessionInterruptionNotification and am handling it with the following code to stop/start the AudioSession and AudioUnit. (Note: after a lot of googling most of the recommendations seem to revolve around adding an additional call on -applicationWillResignActive to end the interruption in case it's not fired, so I added this as well):
- (void)setActive:(BOOL)active {
NSError *activationError = nil;
BOOL success = [[AVAudioSession sharedInstance]
setActive:active
error:&activationError];
if (success) {
[self.audioUnit setActive:active];
} else {
[self.audioUnit setActive:NO];
}
active_ = self.audioUnit.isActive;
}
- (void)audioSessionInterrupted:(NSNotification *)notification {
NSDictionary *interruptionDict = [notification userInfo];
NSNumber *interruptionType = [interruptionDict valueForKey:AVAudioSessionInterruptionTypeKey];
if ([interruptionType integerValue] == AVAudioSessionInterruptionTypeBegan) {
NSLog(@"AudioSession Interruption Began");
_isInterrupted = YES;
[self setActive:NO];
} else if ([interruptionType integerValue] == AVAudioSessionInterruptionTypeEnded) {
NSLog(@"AudioSession Interruption Ended");
[self endInterruptionIfNecessary];
}
}
- (void)endInterruptionIfNecessary {
if (self.isInterrupted && [[UIApplication sharedApplication] applicationState] != UIApplicationStateBackground) {
[self setActive:YES];
_isInterrupted = NO;
}
}
Now it seems to be consistently trying to restart the session/unit after an interruption but now I get this error every time after returning to the app and obviously the audio still doesn't restart.
16:11:59.545 <com.apple.main-thread> AUIOClient_StartIO failed (-66628)
16:11:59.552 <AURemoteIO::IOThread> AURemoteIO@0x1f434c20: IOThread exiting with error 0x10004006
16:11:59.588 <com.apple.main-thread> AUIOClient_StartIO failed (-66628)
I've tried searching for the error code in the headers and internet but not having any luck. If anyone has any pointers or thoughts as to where it's going wrong I'd be much appreciative.
Thanks,
Joe
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden