【问题标题】:Convert MPEG audio files downloaded through AlamoFire to mp3 files将通过 AlamoFire 下载的 MPEG 音频文件转换为 mp3 文件
【发布时间】: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


    【解决方案1】:

    添加“.mp3”路径扩展名

    不会改变文件格式。 您应该转换您的音频文件。但是您不能在 iOS 设备上创建 .mp3 文件。

    【讨论】:

    • 作为替代方案,您可以在 iOS 设备上创建 .mp4。
    猜你喜欢
    • 1970-01-01
    • 2015-03-17
    • 2020-04-21
    • 2020-04-29
    • 2011-03-16
    • 2013-11-12
    • 1970-01-01
    • 2011-11-09
    • 2023-03-23
    相关资源
    最近更新 更多