I need to setup max size for file which is recording. I tried to use this method, but it updates the size once in 2-3 seconds. But I am trying to update it each 1 second with timer. But it returns the same size each time and updates once in 2-3 seconds.
func updateSlider() {
let attr = try FileManager.default.attributesOfItem(atPath: url.path)
let dict = attr as NSDictionary
let fileSize = Int(dict.fileSize())
}
Is there any way to set max file size for AVAudioRecorder?
This is not possible with
AVAudioRecorder.You could calculate the moving average and interpolate the missing values. You could do that at a higher frequency to smooth progress.
Alternatively you could use lower level AVFoundation APIs to get to the data and write that to a file yourself.
Assuming the maximum file size doesn't need to be very accurate, I'd be pragmatic and use the former method.
Then, if you'd round the values shown on the UI (e.g. to 1k or 10k bytes), you'll hide insignificant information and get a better UX.