0
我從我們製作的應用程序中獲取了這些代碼,這些代碼已經存在(並且仍然正常運行)。 但是,當我嘗試在新應用中運行它時,我收到了一個SIGABRT。SIGABRT當使用AVFoundation
這裏有一個示例類,我用它來通過DependencyService再現Xamarin.Forms中的崩潰。創建記錄器後,錯誤屬性保持爲空。
public class RedordDependencies : IRecordDependencies
{
NSObject[] values = new NSObject[] {
NSNumber.FromFloat (44100.0f), //Sample Rate
NSNumber.FromInt32 ((int)AudioToolbox.AudioFormatType.LinearPCM), //AVFormat
NSNumber.FromInt32 (2), //Channels
NSNumber.FromInt32 (16), //PCMBitDepth
NSNumber.FromBoolean (false), //IsBigEndianKey
NSNumber.FromBoolean (false) //IsFloatKey
};
NSObject[] keys = new NSObject[] {
AVAudioSettings.AVSampleRateKey,
AVAudioSettings.AVFormatIDKey,
AVAudioSettings.AVNumberOfChannelsKey,
AVAudioSettings.AVLinearPCMBitDepthKey,
AVAudioSettings.AVLinearPCMIsBigEndianKey,
AVAudioSettings.AVLinearPCMIsFloatKey
};
AVAudioRecorder recorder;
NSError error;
NSDictionary settings;
public RedordDep()
{
settings = NSDictionary.FromObjectsAndKeys(values, keys);
}
public string Prepare()
{
NSUrl path = NSUrl.FromString(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), DateTime.Now.Ticks.ToString() + ".wav"));
recorder = AVAudioRecorder.Create(path, new AudioSettings(settings), out error);
bool prepared = recorder.PrepareToRecord();
return path.Path;
}
}
編輯: 我發現這個使用AVFoundation時也發生在其他情況下。 在我的情況下,當我嘗試初始化錄像機和錄音機時就發生了這種情況。