我正在使用Alamofire API在我的iOS项目中下载内容。效果很好,但我只想下载音频内容并将其作为mp3存储到我的文件目录中。 mp3文件下载很好,但是存在一些我想下载的音频内容,并且没有路径扩展名。没有扩展名的Audi内容将下载并仍可以从我的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
}
})
最佳答案
adding the ".mp3" path extension
不会更改文件格式。
您应该转换音频文件。但是您无法在iOS设备上创建.mp3文件。
关于ios - 将通过AlamoFire下载的MPEG音频文件转换为mp3文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62587007/