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

发布于 2024-11-05 02:51:08 字数 1515 浏览 0 评论 0原文

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

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 对象返回 null 值。

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

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;

提前致谢。

For the last 2 years, I'm using the next code to init an audio recorder object, and everything has been fine.

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

However, this week I made an upgrade to: Mono 2.10.2, MonoTouch 4.0.1.10285, MonoDevelop 2.4.2. I'm still using Xcode 3.2.6 and iOS SDK 4.3. With this configuration, the method

AVAudioRecorder.ToUrl(url, settings, out errorRecorder)

always returned a null value to the ar object.

Somebody has the same problem? This is the complete code:

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;

Thanks in advanced.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱给你人给你 2024-11-12 02:51:08

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

更改:AudioFileType.M4A
至:AudioFormatType.M4A

更改:AVAudioSettings.AVFormatKey
至:AVAudioSettings.AVFormatIDKey

The change happened in the settings object. If you read apples documentation it matches the examples. This should do it for you.

Change: AudioFileType.M4A
To: AudioFormatType.M4A

And

Change: AVAudioSettings.AVFormatKey
To: AVAudioSettings.AVFormatIDKey

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文