'AVFAudio - Is it safe to perform file copy immediately after AVAudioRecorder.stop()

We start a voice recording via

self.avAudioRecorder = try AVAudioRecorder(
    url: self.recordingFileUrl, 
    settings: settings
)
self.avAudioRecorder.record()

At certain point, we will stop the recording via

self.avAudioRecorder.stop()

I was wondering, is it safe to perform file copy on self.recordingFileUrl immediately, after self.avAudioRecorder.stop()?

Is all recording data has been flushed to self.recordingFileUrl and self.recordingFileUrl file is closed properly?



Solution 1:[1]

It seems safer to perform file saving in audioRecorderDidFinishRecording(_:successfully:)

Source: https://developer.apple.com/forums/thread/705561

It does seem to be synchronous, though in theory something could still fail at that point, so it is safer to use the delegate method audioRecorderDidFinishRecording(_:successfully:), rather than make an assumption that the recording will always succeed after calling stop.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cheok Yan Cheng