[英]AVAudioRecorder is always null
I have been trying to record audio in xamarin forms there was no direct way to do it so i was trying to achieve it through custom rendering and i have followed the example from here . 我一直试图以xamarin形式录制音频,没有直接的方法可以做到,所以我试图通过自定义渲染来实现它,并且我从这里开始遵循示例。
// AVAudioRecorder Creation //创建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);
However in the code "recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out error);" 但是,在代码“ recorder = AVAudioRecorder.Create(url,新的AudioSettings(settings),出错误)”中。 is always null 始终为null
Any help would be much appreciated. 任何帮助将非常感激。
I have fixed it by myself, made this working by changing the audio settings as follows 我已经自行修复,可以通过如下更改音频设置来使其正常工作
`var settings = new AudioSettings
{
SampleRate = 44100.0f,
Format = AudioFormatType.LinearPCM,
NumberChannels = 1,
LinearPcmBitDepth = 16,
AudioQuality = AVAudioQuality.High,
};`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.