AVAudioConverter 在 iOS 10 中似乎坏了。该代码在 iOS 9 中运行,现在
错误域=NSOSStatusErrorDomain 代码=-50 "(null)"
无论使用什么音频格式都会返回。每年都让我感到惊讶,基本的库功能停止工作。
func audioConverterFailureIOS10() {
// Describe the audio format
let inFormat = AVAudioFormat(standardFormatWithSampleRate: 44100, channels: 2)
let outFormat = AVAudioFormat(standardFormatWithSampleRate: 22050, channels: 2)
// Allocate buffers
let outBuffer = AVAudioPCMBuffer(pcmFormat: outFormat, frameCapacity: 1024)
// Create an input block that is called when the converter needs input
let inputBlock : AVAudioConverterInputBlock = { (inNumPackets, outStatus) -> AVAudioBuffer? in
// Fails before entering here
return nil
}
// Create the audio converter
let converter = AVAudioConverter(from: inFormat, to: outFormat)
var error : NSError?
_ = converter.convert(to: outBuffer, error: &error, withInputFrom: inputBlock)
// Error Domain=NSOSStatusErrorDomain Code=-50 "(null)"
print(error)
}