I have a problem in an app I'm developing where eventually too many audio files wind up being open. I haven't found any way to close the files, so I've tried setting files that aren't being used to nil, but the problem is persisting.
I've declared the audio files as non-optionals, ex:
let audioFile1 = AKAudioFile!
and in the method they are being initialized, the initialization fails (after too many files have been opened) in the following block of code (audioUrl is a one of the method's parameters):
var audioFileOpt: AKAudioFile?
do {
audioFileOpt = try AKAudioFile(forReading: audioUrl)
} catch let error {
print("Error reading url: ", audioUrl)
print(error.localizedDescription)
}
This is the error that is returned: The operation couldn\U2019t be completed. (com.apple.coreaudio.avfaudio error -42.)
, which is a CoreAudio error (kAudio_TooManyFilesOpenError).
I'd appreciate any advice on how to go about solving this.