I'm currently downloading audio files from Firebase saving them locally and listing them in a tableview. Im getting the local directory like this:
file:///var/mobile/Containers/Data/Application/6C72433F-4DF0-4976-BBDE-36F6B5C23E6D/Documents/nJNJwVNMrmUGj9uszManQmMOZf52_NO:1.m4a
When i try to play an audio file with AVAudioPLayer i get the error:
Error Domain=NSOSStatusErrorDomain Code=2003334207 "(null)"
I've been stuck on this for three days and would really appreciate someone pointing me in the right direction. If any further code is needed to help solve this let me know. Thanks.
This is my code for playing the audio:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//Access the cell tapped on and the path to the recording the user wants to listen to
let path = findDirectory(filename:userID + "_NO:" + String(recordingNumber)).appendingPathComponent("\(indexPath.row + 1).m4a")
do {
self.audioPlayer = try AVAudioPlayer(contentsOf: path)
self.audioPlayer.play()
} catch let error as NSError {
print(error.description)
}
}
My code for finding the directory is here:
func findDirectory(filename:String) -> URL {
let fileManager = FileManager.default
let urls = fileManager.urls(for: .documentDirectory, in: .userDomainMask)
let docDirectory = urls[0] as URL
let soundURL = docDirectory.appendingPathComponent("\(filename).m4a")
print(soundURL)
return soundURL
}