将 AVAudioRecorder.ToUrl() 与 MonoTouch 4.0.1 一起使用返回 null
在过去的两年里,我使用下一个代码来初始化录音机对象,一切都很好。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改发生在设置对象中。如果您阅读苹果文档,它会与示例相匹配。这应该适合你。
更改:
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