gpt4 book ai didi

c# - 将 AVAudioRecorder.ToUrl() 与 MonoTouch 4.0.1 一起使用返回 null

转载 作者:行者123 更新时间:2023-11-29 13:49:03 25 4
gpt4 key购买 nike

在过去的 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;

提前致谢。

最佳答案

更改发生在设置对象中。如果您阅读苹果文档,它会与示例相匹配。这应该为您完成。

更改:AudioFileType.M4A至:AudioFormatType.M4A

更改:AVAudioSettings.AVFormatKey至:AVAudioSettings.AVFormatIDKey

关于c# - 将 AVAudioRecorder.ToUrl() 与 MonoTouch 4.0.1 一起使用返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5878394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com