Reputation: 1295
AVAudioPlayer has been giving me the following error on some local MP3 files:
Error Domain=NSOSStatusErrorDomain Code=-54 "(null)"
I'm downloading a zip file to the Documents directory, then unzipping using a library called SSZipArchive.
In the Documents directory, a folder is created to contain the unzipped files.
I was able to play entire albums without any issues. Everything was going fine until I start downloading certain files.
I've looked for similar questions (osx), possibly stating that this is a permission error, but I haven't managed to make it work.
Does anyone know what this error is? It seems to not be on any documentation either.
Ex.
let fileManager = NSFileManager.defaultManager()
var docDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
func showContentsOfSubDirectories() {
do {
let files = try fileManager.contentsOfDirectoryAtPath(docDirectory)
print("----")
for file in files {
print("> \(file)")
do {
var rsrc: AnyObject?
let possibleDir = NSURL(fileURLWithPath: docDirectory + "/" + file)
try possibleDir.getResourceValue(&rsrc, forKey: NSURLIsDirectoryKey)
if let isDirectory = rsrc as? NSNumber {
if Bool(isDirectory) {
let subFiles = try fileManager.contentsOfDirectoryAtPath(docDirectory + "/" + file)
for subFile in subFiles {
print(" >> \(subFile)")
}
}
}
} catch let error as NSError {
print(error)
}
}
print("----")
} catch let error as NSError {
print(error)
}
}
I use the above code for checking the directory. This would give me in debugging:
ALBUM NAME
SONG1.mp3
SONG2.mp3
SONG3.mp3
SONG4.mp3
So it exists.
let filePath = docDirectory + "/" + ALBUM_NAME + "/SONG1.mp3"
// ~/Library/Developer/CoreSimulator/Devices/XXX/data/Containers/Data/Application/XXX/
// Same issue happens on actual device too
do {
try player = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: filePath!))
} catch let error as NSError {
}
This works on some and doesn't on others.
Upvotes: 1
Views: 1902
Reputation: 699
I hit the same error and I can confirm that it was (at least, in my case) a permissions error. Specifically, related to the NSFileProtectionKey
.
Setting NSFileProtectionKey
to NSFileProtectionNone
solves it.
Upvotes: 3