6

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)
}
4

1 回答 1

7

因此,事实证明必须将 outBuffer frameLength 设置为 frameCapacity。默认情况下,长度为 0,显然在 iOS 10 上的处理方式不同

于 2016-09-29T20:02:19.197 回答