我在使用Swift编写的iOS应用程序中遇到一个.m4a声音文件的奇怪问题。
以下是发生的事情:
以下是我认为的相关代码,如果您认为我应该添加更多内容,请告诉我。
从AWS S3存储桶下载文件的代码:
let transferUtility = AWSS3TransferUtility.default()
transferUtility.downloadData(
fromBucket: "mybucket",
key: "xyz.m4a",
expression: expression,
completionHandler: completionHandler
).continueWith {
(task) -> AnyObject! in if let error = task.error {
print("Error: \(error.localizedDescription)")
}
if let _ = task.result {
// Do something with downloadTask.
print("task.result -- OK!")
let downloadOutput = task.result
print("downloadOutput:\(String(describing: downloadOutput))")
}
return nil;
}
这是completionHandler部分:
var completionHandler: AWSS3TransferUtilityDownloadCompletionHandlerBlock?
completionHandler = {
[weak self] (task, URL, data, error) -> Void in
DispatchQueue.main.async(execute: {
print("transfer completion OK!")
let localFileName = "xyz.m4a",
playFileURL = self?.getDocumentsURL().appendingPathComponent(localFileName)
FileManager.default.createFile(atPath: (playFileURL?.path)!,
contents: data,
attributes: nil)
if FileManager.default.fileExists(atPath: (playFileURL?.path)!) {
print("playFileURL present!") // Confirm that the file is here!
}
})
}
播放下载声音文件的代码:
let fileName = "xyz.m4a",
audioFile = getDocumentsURL().appendingPathComponent(fileName)
if !FileManager.default.fileExists(atPath: audioFile.path) {
print("We have no file !!!!!") // Just in case the file was not found!
}
// This code assumes the file exists.
do {try soundSession.setCategory(AVAudioSessionCategoryPlayback)
try soundSession.setActive(true)
if audioPlayer == nil {
audioPlayer = try AVAudioPlayer(contentsOf: audioFile,
fileTypeHint: AVFileType.m4a.rawValue)
guard let _ = audioPlayer else {return}
audioPlayer.delegate = self
}
audioPlayer.play()
} catch let error {
print("Error:\n" + error.localizedDescription)
}
最后这是我得到的错误:
Error:
The operation couldn’t be completed. (OSStatus error 1685348671.)
我希望有人能看到错误,告诉我问题所在。