C# AVAudioRecorder始终为空
我一直在尝试以xamarin的形式录制音频,但没有直接的方法,所以我尝试通过自定义渲染来实现它,并遵循了中的示例 //AVAudioRecorder创建C# AVAudioRecorder始终为空,c#,ios,xamarin,xamarin.forms,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[] { N
//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);
但是在代码中,“recorder=AVAudioRecorder.Create(url、新音频设置(设置)、out错误);”始终为空
任何帮助都将不胜感激。我自己修复了它,通过如下更改音频设置使其正常工作
`var settings = new AudioSettings
{
SampleRate = 44100.0f,
Format = AudioFormatType.LinearPCM,
NumberChannels = 1,
LinearPcmBitDepth = 16,
AudioQuality = AVAudioQuality.High,
};`
错误是什么?System.NullReferenceException,bcuz recorder为null@BugFinder这不是原因。。错误是告诉您它失败了。“音频设置”功能中有什么?