开发者

Using AVAudioRecorder.ToUrl() with MonoTouch 4.0.1 return null

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜