没有音频硬件可用时调用AudioUnitInitialize()

时间:2012-05-03 10:33:14

标签: iphone ios core-audio audiounit

在iOS应用程序项目中,我有一个音频单元(用于输入/输出)初始化代码(在设置各种属性,回调等之后)以:

结束
OSErr err = AudioUnitInitialize (self.audioUnit);
NSAssert1 (err == noErr, "Error initializing audio unit: %ld", err);

我的问题是,在某些情况下,我必须在计算机上运行此代码(当然在iPhone模拟器中),没有可用的音频硬件,然后发生以下情况:

首先,在控制台上,我收到以下消息(对于长行而言,对我来说似乎更清楚,没有额外的换行符):

2012-05-03 12:41:15.020 TimeKeeper[452:10703] Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn:  dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
  Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
  Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-05-03 12:41:15.140 TimeKeeper[452:10703] Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn:  dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
  Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
  Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-05-03 12:41:15.207 TimeKeeper[452:10703] Error '!obj' trying to fetch default input device's sample rate
2012-05-03 12:41:15.209 TimeKeeper[452:10703] Error getting audio input device sample rate: '!obj'

然后大约2分钟左右通过,直到AudioUnitInitialize返回错误代码0(即noErr),并在控制台上显示此消息:

2012-05-03 12:43:45.222 TimeKeeper[452:14403] AQMEIO_Base::DoStartIO: timeout
2012-05-03 12:43:45.226 TimeKeeper[452:14403] AQMEDevice(0x7b0de00)::StartIO: error -66681

如果我再调用AudioOutputUnitStart,则该函数再次返回约2分钟,但至少返回状态不为零。

我希望能够判断音频硬件是否不可用,因此我可以避免首先调用AudioUnitInitialize - 或者至少获得非零返回状态而不必等待这么久(在app运行时条款中)。

1 个答案:

答案 0 :(得分:1)

您可以随时检查运行模拟的iOS代码并执行其他操作。

#if TARGET_IPHONE_SIMULATOR
    // stub out audio unit with a unit test, unix pipe, or etc.
#endif