IPhone SDK: Audio session error: -12986 .... after upgrading to 3.1
I am creating an iPhone iPhone App using Audio Sessions. The prototype functioned until I decided to upgrade to 3.1
After a lot of hunting, I finally found that the session activation call ended with error code 12986. I could not find the reason for this. The NSError object gives no details. I used localized * APIs for more information and this is what I got:
localizedDescription: The operation could not be performed. ( OSStatus error -12986 ). localizedFailureReason:<blank>
localizedRecoverySuggestion: <blank>
Does anyone know how to find more information on such error codes?
In the meantime, I will keep digging and updating this if the status changes.
My code for the curious is
NSError *myErr;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&myErr];
bSuccess= [audioSession setActive: YES error: &myErr];
source to share
Don't know what 12986 means, but it looks like it's now tied to the audio capabilities of the device. And I have a solution!
I noticed that this error only appears when I am using the iTouch and not the IPhone. Since I was setting the session category as PlayAndRecord to and , I decided to check if it didn't interfere with iTunes. Made the code a little smarter to detect if AudioInputIsAvailable
and then set the category appropriately ( PlayBack
on iTouch and PlayAndRecord
iPhone). This fixed it!
So it looks like this was ignored in previous SDKs. I haven't changed anything before. :-)
Corrected code below:
NSError *myErr;
BOOL bSuccess = FALSE;
BOOL bAudioInputAvailable = FALSE;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
bAudioInputAvailable= [audioSession inputIsAvailable];
if( bAudioInputAvailable)
{
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&myErr];
}
else {
[audioSession setCategory:AVAudioSessionCategoryPlayback error:&myErr];
}
bSuccess= [audioSession setActive: YES error: &myErr];
if(!bSuccess)
{
NSLog(@"Unable to Start Audio Session. Terminate Application.");
NSLog([myErr localizedDescription]);
NSLog([myErr localizedFailureReason]);
NSLog([myErr localizedRecoverySuggestion]);
}
source to share
I had similar problems trying to extract useful information from an error object, as well as performing operations on the underlying data, I found the following code helpful to more accurately determine the cause of the error.
NSError *error;
... your code here ...
NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
if(detailedErrors != nil && [detailedErrors count] > 0)
{
for(NSError* detailedError in detailedErrors)
{
NSLog(@" DetailedError: %@", [detailedError userInfo]);
}
}
else
{
NSLog(@" %@", [error userInfo]);
}
Sorry I was unable to help you with your audio problem.
NTN
source to share