使用AVAudioRecorder.ToUrl()与MonoTouch 4.0.1返回null

本文关键字:返回 null MonoTouch AVAudioRecorder ToUrl 使用 | 更新日期: 2023-09-27 17:54:27

在过去的2年里,我使用下一个代码来初始化一个录音机对象,一切都很好。

ar = AVAudioRecorder.ToUrl(url, settings, out errorRecorder);
ar.MeteringEnabled = false;

然而,本周我升级到:Mono 2.10.2, MonoTouch 4.0.1.10285, MonoDevelop 2.4.2。我仍然使用Xcode 3.2.6和iOS SDK 4.3。在这个配置中,方法

AVAudioRecorder.ToUrl(url, settings, out errorRecorder)

总是返回一个空值给ar对象。

有人有同样的问题吗?这是完整的代码:

NSError errorRecorder;
NSUrl url;
NSDictionary settings;
AVAudioRecorder ar;
string path, audioFile;
NSObject[] values = new NSObject[]
{
    NSNumber.FromInt32((int)AudioFileType.M4A), 
    NSNumber.FromFloat(11025.0f), 
    NSNumber.FromInt32(1),
    NSNumber.FromInt32((int)AVAudioQuality.Min)
};
NSObject[] keys = new NSObject[]
{
    AVAudioSettings.AVFormatKey,
    AVAudioSettings.AVSampleRateKey,
    AVAudioSettings.AVNumberOfChannelsKey,
    AVAudioSettings.AVEncoderAudioQualityKey
};
settings = NSDictionary.FromObjectsAndKeys (values, keys);
path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
path = Path.Combine(path, audioDir);
if (!Directory.Exists(path)){
    Directory.CreateDirectory(path);
}
audioFile = newJobEntity.jobid + "_" + numFiles + ".caf";
if (!File.Exists(Path.Combine(path, audioFile)))
    FileStream audioFileStream = File.Create(Path.Combine(path, audioFile));
url = NSUrl.FromFilename(Path.Combine(path, audioFile));
ar = AVAudioRecorder.ToUrl(url, settings, out errorRecorder);
ar.MeteringEnabled = false;

使用AVAudioRecorder.ToUrl()与MonoTouch 4.0.1返回null

设置对象发生更改。如果您阅读apple文档,它与示例匹配。这应该可以满足你的要求。

改变:AudioFileType.M4ATo: AudioFormatType.M4A

改变:AVAudioSettings.AVFormatKeyTo: AVAudioSettings.AVFormatIDKey