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)
}
答案 0 :(得分:4)
因此,事实证明outBuffer frameLength必须设置为frameCapacity。默认情况下,长度为0,显然在iOS 10上的处理方式不同