使用swift问题下载youtube视频

时间:2017-05-10 11:46:06

标签: ios swift download youtube alamofire

我想在youtube上下载视频链接。 我收到了下载链接,但下载后,该文件没有扩展名(附件是图像Video saved name

我使用alamofire下载视频

    var destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)


         destination = { (tempURL:URL,resp:HTTPURLResponse) in
            let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory,
                                                                    .userDomainMask, true)[0]
            let documentsURL = URL(fileURLWithPath: documentsPath, isDirectory: true)
            var fileURL:URL = documentsURL.appendingPathComponent(resp.suggestedFilename!)

            return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
        }
self.request=Alamofire.download((url.absoluteString), to: destination)
        .downloadProgress { progress in
            print("Download Progress: \(progress.fractionCompleted)")
            self.progressView.setProgress(value: CGFloat(progress.fractionCompleted)*100, animationDuration: 0)
        }
        .responseData { response in


            self.request=nil

            if response.result.value != nil {

                self.videoDetails["date"]=String(describing: NSDate())
                self.videoDetails["videoPath"]=response.destinationURL?.path
                self.progressView.setProgress(value: 0, animationDuration: 0)
                }
}

我怎么能用真正的扩展名下载文件。 我尝试为它添加像mp4这样的扩展程序,但我无法播放视频

0 个答案:

没有答案