【发布时间】:2020-06-26 02:18:24
【问题描述】:
我正在使用 Alamofire API 下载我的 iOS 项目中的内容。它很好用,但我只想下载音频内容并将其作为 mp3 存储到我的文件目录中。 Mp3 文件下载正常,但存在一些我想要下载且没有路径扩展名的音频内容。没有扩展名的奥迪内容被下载,仍然可以从我的 AVAudioPlayer() 播放,但我还需要将这些文件转换为 mp3。
有没有办法将这些没有扩展名的音频文件转换为 mp3?我尝试简单地添加“.mp3”路径扩展名,但我认为没有那么简单。任何帮助将不胜感激。
// Download Destination
let dest: DownloadRequest.DownloadFileDestination = { _, _ in
let documentsURL:NSURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! as NSURL
print("***documentURL: ",documentsURL)
let fileURL = documentsURL.appendingPathComponent(url.lastPathComponent)
print("***fileURL: ",fileURL ?? "")
return (fileURL!,[.removePreviousFile, .createIntermediateDirectories])
}
// Download Operation
Alamofire.download(url, to: dest)
.downloadProgress(closure: {(progress) in
print("Progress: \(progress.fractionCompleted)")
self.appDelegate.downloadProgressQueue[url] = Float(progress.fractionCompleted)
}).validate(contentType: ["audio/mpeg"])
.response(completionHandler: {(complete) in
if complete.error == nil, let filePath = complete.destinationURL?.path {
// Download Completed
}
else {
// Download Unsuccessful
}
})
【问题讨论】:
标签: ios swift audio alamofire mp3