I am trying to record audio using AVAudioRecorder.
If I try to record with the following configuration, I find that the recording is successful,
let settings: [String: Any] = [
AVFormatIDKey: kAudioFormatMPEG4AAC,
AVSampleRateKey: 22050,
AVEncoderBitRateKey: 128000,
AVNumberOfChannelsKey: 2,
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
]
try audioRecorder = AVAudioRecorder(url: audioFileURL, settings: settings)
audioRecorder?.delegate = self
If I try to record with after changing the bit rate, I find that the recording is not successful.
let settings: [String: Any] = [
AVFormatIDKey: kAudioFormatMPEG4AAC,
AVSampleRateKey: 22050,
AVEncoderBitRateKey: 160000,
AVNumberOfChannelsKey: 2,
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
]
try audioRecorder = AVAudioRecorder(url: audioFileURL, settings: settings)
audioRecorder?.delegate = self
In the debug console, the following message is shown when `audioRecorder.record()` is called but no errors are thrown
2125: AudioCodecInitialize failed
Can anyone point how to detect this condition as errors are not thrown?
Edit - I have implemented the delegate method func audioRecorderEncodeErrorDidOccur(_ recorder: AVAudioRecorder, error: Error?) so shouldn't this method be called if audioRecorder failed for any reason.