I\'m testing my app in simulator.
I\'m downloading file and getting it\'s local way like this one:
file:///Users/administrator/Library/Developer/CoreSimulator/
let fileName = ("FILE_NAME.mp3")
let documentsDirectory = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
let soundFileURL = documentsDirectory.URLByAppendingPathComponent(fileName)
AudioCenter.player.playURL(soundFileURL)
Look at NSFileManager. The method URLForDirectory:inDomain:appropriateForURL:create:error:
is what you should use.
// create the soundFileURL for the word
let toAppendString = "\(String)" //
let documentsDirectory = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
soundFileURL = documentsDirectory.URLByAppendingPathComponent(toAppendString)
do {
self.player = try AVAudioPlayer(contentsOfURL: soundFileURL)
player.prepareToPlay()
player.volume = 1.0
player.play()
} catch let error as NSError {
print(error)
}
Under iOS8, the path that you have saved won't be valid across launches. The id you see "E5F13797-A6A8-48A1-B3C3-FBC3D7A03151" will change with each launch.
The solution is to save the filename and not the complete path, and to recreate the URL or complete path, by getting the path to the Documents (or tmp) folder and appending the filename to it.