AVAudioFile InitForWriting

TimPurdumTimPurdum USMember ✭✭

I have the following code that works perfectly to record tracks on iOS.

string Documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

AudioSettings RecordSettings = new AudioSettings();
RecordSettings.Format = AudioToolbox.AudioFormatType.MPEG4AAC;
RecordSettings.EncoderAudioQualityForVBR = AVAudioQuality.Max;
RecordSettings.NumberChannels = 2;
RecordSettings.SampleRate = SoundPlayer.PlaybackMixerNode.GetBusInputFormat(0).SampleRate;

var url = new NSUrl(Path.Combine(Documents, "track" + CurrentTrack + ".aac"));
var trackFile = new AVAudioFile(url, RecordSettings, out error);

However, the same code fails on MacOS, with the error:
Could not initialize an instance of the type 'AVFoundation.AVAssetExportSession': the native 'initWithAsset:presetName:' method returned nil.

I have tried messing with the path, adding the "Documents" folder, and printing out the path, which I can get to: /Users/username/Documents/Xylophone/track1.aac, but this doesn't change the error. I have also tried loading with and without the AudioSettings, no change.

Tagged:

Best Answer

  • TimPurdumTimPurdum US ✭✭
    Accepted Answer

    OK, my block that initialized the AudioSettings wasn't being called, and so I was passing in null for that variable. My bad on that. On to the next bug!

Answers

  • TimPurdumTimPurdum USMember ✭✭
    Accepted Answer

    OK, my block that initialized the AudioSettings wasn't being called, and so I was passing in null for that variable. My bad on that. On to the next bug!

Sign In or Register to comment.