[英]Convert MPEG audio files downloaded through AlamoFire to mp3 files
我正在使用 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
}
})
添加“.mp3”路径扩展名
不会改变文件格式。 您应该转换您的音频文件。 但是您不能在 iOS 设备上创建.mp3 文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.