【问题标题】:IPhone SDK: Audio Session Error: -12986 .... after upgrade to 3.1iPhone SDK:音频会话错误:-12986 .... 升级到 3.1 后
【发布时间】:2009-10-08 20:00:23
【问题描述】:

我正在使用 Audio Sessions 构建 iPhone 音频应用程序。原型一直在运行,直到我决定升级到 3.1

经过大量搜索,我终于发现会话激活调用失败,错误代码为 12986。 我无法在任何地方找到原因。 NSError 对象没有给出任何细节。我使用本地化* API 来获取更多信息,这就是我得到的:

localizedDescription:操作无法完成。 (OSStatus 错误 -12986。) 本地化失败原因:<blank>

localizedRecoverySuggestion:<blank>

有人知道如何找到有关此类错误代码的更多信息吗?

同时,如果我的状态发生变化,我会继续挖掘和更新。

我的好奇代码是 -

NSError *myErr;
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&myErr];
bSuccess= [audioSession setActive: YES error: &myErr];  

【问题讨论】:

  • 请包含定义 myErr 的行

标签: iphone core-audio


【解决方案1】:

不知道 12986 的确切含义,但它现在似乎与设备的 音频功能 相关联。我有一个解决方案!

我注意到这个错误只有在我使用 iTouch 时才会弹出,而不是在 iPhone 上。由于我在 both 上将会话类别设置为 PlayAndRecord,因此我决定检查这是否在 iTouch 上搞砸了。使代码更智能地检测AudioInputIsAvailable,然后相应地设置类别(ITouch 上的PlayBack 和iPhone 上的PlayAndRecord)。这解决了它!

所以看起来这在之前的 SDK 中被忽略了。我之前没有改变任何东西。 :-)

以下更正代码:

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

【讨论】:

  • 非常感谢,我感觉缺少麦克风与此有关。用户的 iPod 因 AudioUnitInitialize 中的相同错误而失败。我很确定更智能的会话处理会为我解决这个问题。
  • 这篇文章是我在 OSStatus 错误代码 -12986 上找到的唯一内容,果然,我遇到了同样的问题。干杯
【解决方案2】:

我在尝试从错误对象中提取有用信息时也遇到了类似的麻烦,在执行核心数据操作时,我发现以下代码有助于更准确地确定错误原因。

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

很抱歉,我无法帮助您解决音频问题。

HTH

【讨论】:

猜你喜欢
  • 2012-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多