【问题标题】:How to search the error code of 'com.apple.coreaudio.avfaudio'?如何搜索“com.apple.coreaudio.avfaudio”的错误代码?
【发布时间】:2017-07-13 07:32:14
【问题描述】:
在哪里可以得到com.apple.coreaudio.avfaudio错误码的信息,如:
由于未捕获的异常“com.apple.coreaudio.avfaudio”而终止应用程序,原因:“错误 -50”
我在将 PCM 缓冲区写入 AVAudioFile 时总是出错。缓冲区来自AVAudioEngine 的输出节点。
错误:
* 由于未捕获的异常“com.apple.coreaudio.avfaudio”而终止应用程序,原因:“错误 -50”
* 首先抛出调用栈:
(0x18eb46fe0 0x18d5a8538 0x18eb46eb4 0x1a8d051cc 0x1a8d731dc 0x1000d45e0 0x1000d4820 0x1a8d14654 0x1a8d146c0 0x1a8d8c26c 0x1a8d8c1fc 0x100ae5a10 0x100af1a84 0x100b001f8 0x100ae7a60 0x100af3128 0x100ae9634 0x100af5630 0x100af6f48 0x18dc0968c 0x18dc0959c 0x18dc06cb4)
libc++abi.dylib:以 NSException 类型的未捕获异常终止
你能帮帮我吗?
【问题讨论】:
标签:
avaudioengine
avaudiofile
【解决方案2】:
我没有找到错误的确切描述,但它似乎是一个通用的“无效参数”异常。
在我的情况下,很可能在你的情况下,问题是 buffer 和 AVAudioFile 实例的格式不匹配。
let settings: [String: Any] = [
AVFormatIDKey: kAudioFormatLinearPCM,
AVSampleRateKey: 44 * 1000,
AVNumberOfChannelsKey: 2
]
do {
try avFile = AVAudioFile(forWriting: URLFor(filename: "test.caf"), settings: settings)
avEngine.inputNode?.installTap(onBus: 0, bufferSize: 1024, format: avEngine.mainMixerNode.outputFormat(forBus: 0)) {
buffer, time in
do {
try self.avFile?.write(from: buffer)
}
catch {
// TODO
}
}
try avEngine.start()
} catch {
// TODO
}
在下面的示例中,当我以 PCM、2 通道 44khz 以外的任何格式创建 AVAudioFile 时,我遇到了 “-50” 错误。
【解决方案3】:
我遇到了类似的问题,我遇到了 com.apple.coreaudio.avfaudio -50 错误,并且采样率不匹配。我只需要设置 AVAudioFile 以匹配 mainMixerNode outputFormat。
let format = engine.mainMixerNode.outputFormat(forBus: 0)
self.musicTrackFinalOutputFile = try AVAudioFile(forWriting: temporaryFileURL, settings: [
AVFormatIDKey: NSNumber(value:kAudioFormatMPEG4AAC),
AVEncoderAudioQualityKey : AVAudioQuality.high.rawValue,
AVEncoderBitRateKey : 320000,
AVNumberOfChannelsKey: format.channelCount,
AVSampleRateKey : format.sampleRate
])