AVAudioRecorder始终为空

Sud*_*dha 2 c# ios xamarin xamarin.forms

我一直在尝试用xamarin表单录制音频,没有直接的方法可以做到这一点所以我试图通过自定义渲染实现它,我已经从这里按照示例.

// AVAudioRecorder创作

        //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary
        NSObject[] values = new NSObject[]
        {
            NSNumber.FromFloat (16000.0f), //Sample Rate
            NSNumber.FromInt32 ((int)AudioToolbox.AudioFormatType.MPEG4AAC), //AVFormat
            NSNumber.FromInt32 (1), //Channels
            NSNumber.FromInt32 (16), //PCMBitDepth  
            NSNumber.FromBoolean (false), //IsBigEndianKey
            NSNumber.FromBoolean (false) //IsFloatKey
        };

        //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary
        NSObject[] keys = new NSObject[]
        {
            AVAudioSettings.AVSampleRateKey,
            AVAudioSettings.AVFormatIDKey,
            AVAudioSettings.AVNumberOfChannelsKey,
            AVAudioSettings.AVLinearPCMBitDepthKey,
            AVAudioSettings.AVLinearPCMIsBigEndianKey,
            AVAudioSettings.AVLinearPCMIsFloatKey
        };

        //Set Settings with the Values and Keys to create the NSDictionary
        settings = NSDictionary.FromObjectsAndKeys (values, keys);

        //Set recorder parameters
        recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out error);
Run Code Online (Sandbox Code Playgroud)

但是在代码"recorder = AVAudioRecorder.Create(url,new AudioSettings(settings),out error);" 永远是空的

任何帮助将非常感激.

Sud*_*dha 5

我自己修复了它,通过更改音频设置使其工作如下

    `var settings = new AudioSettings
        {
            SampleRate = 44100.0f,
            Format = AudioFormatType.LinearPCM,
            NumberChannels = 1,
            LinearPcmBitDepth = 16,
            AudioQuality = AVAudioQuality.High,
        };`
Run Code Online (Sandbox Code Playgroud)