NSAudioStatus的NSOSStatusErrorDomain代码= -54 [英] NSOSStatusErrorDomain Code=-54 for AVAudioPlayer
问题描述
AVAudioPlayer在某些本地MP3文件上给我以下错误:
AVAudioPlayer has been giving me the following error on some local MP3 files:
Error Domain=NSOSStatusErrorDomain Code=-54 "(null)"
我正在将一个zip文件下载到Documents目录,然后使用名为 SSZipArchive 的库将其解压缩.
I'm downloading a zip file to the Documents directory, then unzipping using a library called SSZipArchive.
在Documents目录中,将创建一个文件夹来包含解压缩的文件.
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.
我一直在寻找类似的问题(osx),可能说这是一个权限错误,但是我没有设法使其正常工作.
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.
例如.
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:
相册名称
SONG1.mp3
SONG1.mp3
SONG2.mp3
SONG2.mp3
SONG3.mp3
SONG3.mp3
SONG4.mp3
SONG4.mp3
所以它存在.
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.
推荐答案
我遇到了相同的错误,并且可以确认它是(至少就我而言)权限错误.具体来说,与NSFileProtectionKey
有关.
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
.
将NSFileProtectionKey
设置为NSFileProtectionNone
即可解决此问题.
Setting NSFileProtectionKey
to NSFileProtectionNone
solves it.
这篇关于NSAudioStatus的NSOSStatusErrorDomain代码= -54的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!