#c# #iphone #ios #xamarin.ios #avaudiorecorder
#c# #iPhone #iOS #xamarin.ios #avaudiorecorder
Вопрос:
Последние 2 года я использую следующий код для инициализации объекта audio recorder, и все было нормально.
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;
Заранее благодарю.
Ответ №1:
Изменение произошло в объекте настроек. Если вы читали документацию Apple, она соответствует примерам. Это должно сделать это за вас.
Изменить: AudioFileType.M4A
Для: AudioFormatType.M4A
И
Изменить: AVAudioSettings.AVFormatKey
Для: AVAudioSettings.AVFormatIDKey
Комментарии:
1. Я изменил: AudioFileType.M4A —> AudioFormatType. LinearPCM и изменены: настройки AVAudioSettings. AVFormatKey —> AVAudioSettings. AVFormatIDKey и все работает нормально. Спасибо.
2. У меня тоже работает, спасибо. Но да, нет ключа AudioFormatType.M4A 🙂