开发者

IPhone SDK: Audio Session Error: -12986 .... after upgrade to 3.1

I am building an iPhone audio app using Audio Sessions. Prototype was functioning till I decided to upgrade to 3.1

After a lot of hunting I finally found that the session activation call was failing with error code 12986. I havent been able to find the reason for this anywhere. The NSError object doesnt give any detail. I used the localized* APIs to get more info and this is what I got:

localizedDescription: Operation could not be completed. (OSStatus error -12986.) localizedFailureReason: <blank>

localizedRecoverySuggestion: <blank>

Anyone know how to find more info about such error codes?

Meanwhile开发者_运维知识库 I will continue to dig and update this if my 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];  


Dont know what 12986 means exactly but it appears to be tied to the audio capabilities of the device now. And I have a solution!

I noticed that this error was popping up only when I use an iTouch and not on the IPhone. Since I was setting the session category as PlayAndRecord on both I decided to check if that was messing it up on the iTouch. Made the code a little smarter to detect if AudioInputIsAvailable and then set the Category accordingly (PlayBack on ITouch and PlayAndRecord on iPhone). That fixed it!

So it looks like this was being ignored in the prior SDKs. I had not changed anything earlier. :-)

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]);
}


I've had similar trouble trying to extract useful information from the error object as well when doing core data operations, i found the following code to be helpful in determining more precisely the cause of an 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 couldn't help you out with your audio problem.

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜