【发布时间】:2020-05-31 21:36:00
【问题描述】:
这很可能是我对swift一无所知,但我很困惑..
我有以下(简化的)代码 - 请注意,我已经从中提取了很多内容,因为它(通常)按预期运行:
engine = AVAudioEngine() //engine being a class variable
AVAudioUnit.instantiate(with: mixerDesc, options: [.loadOutOfProcess], completionHandler: {(audioUnit, auError) in
//configure matrix mixer
self.matrixMixer = au
engine.attach(au)
print("make connections")
engine.connect(engine.inputNode, to: au, format: inputFormat)
engine.connect(au, to: engine.mainMixerNode, format: inputFormat)
print("connections done")
try! engine.start()
}
此代码在 99% 的情况下都有效,但是在某些情况下(主要是默认输入/输出设备更改时)在建立连接时会产生错误。我不明白的是,这个错误导致函数在错误发生时退出(建立连接时),但不会导致应用程序终止 - 我假设这是因为错误是只是杀死那个线程。
有什么方法可以捕捉到这个错误吗?我试过在函数的开头添加一个defer {},但这也没有被调用。这令人沮丧,因为这意味着应用程序不同步,我不清楚如何捕捉它。
仅供参考,抛出的错误是:
2020-05-31 22:33:22.219189+0100 StageSound[20887:289670] [General] required condition is false: IsFormatSampleRateAndChannelCountValid(hwFormat)
2020-05-31 22:33:22.221812+0100 StageSound[20887:289670] [General] (
0 CoreFoundation 0x00007fff332f1be7 __exceptionPreprocess + 250
1 libobjc.A.dylib 0x00007fff6c0c95bf objc_exception_throw + 48
2 CoreFoundation 0x00007fff3331ad98
崩溃日志继续..
【问题讨论】:
标签: swift macos cocoa core-audio