在一个 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
首先调用 --- 或者至少获得非零返回状态而不必等待这么长时间(在应用程序运行中 -时间条款)。