【问题标题】:Calling AudioUnitInitialize() when no audio hardware is available当没有音频硬件可用时调用 AudioUnitInitialize()
【发布时间】:2012-05-03 10:33:14
【问题描述】:

在一个 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 --- 或者至少无需等待即可获得非零返回状态长(在应用程序运行时术语中)。

【问题讨论】:

    标签: iphone ios core-audio audiounit


    【解决方案1】:

    您总是可以检查正在运行的模拟 iOS 代码并执行其他操作。

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

    【讨论】:

    • 是的,但有时在模拟器中运行时音频硬件可用。所以我需要一个直接的方法。
    • 模拟器应用是 Mac OS X 应用。您可以随时检查环境变量或在此环境中执行 IOKit 或 QuickTime 调用,而这在 iOS 设备上是无法做到的。
    猜你喜欢
    • 2018-02-24
    • 2020-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    • 2020-10-17
    相关资源
    最近更新 更多