尝试在iOS中使用AVAssetDownloadURLSession下载m3u8视频时出现错误 [英] Getting Error when trying to download a m3u8 video using AVAssetDownloadURLSession in iOS

查看:439
本文介绍了尝试在iOS中使用AVAssetDownloadURLSession下载m3u8视频时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试下载.m3u8视频文件( http://devimages. apple.com/iphone/samples/bipbop/bipbopall.m3u8 )使用AVAssetDownloadURLSession.当我在Xcode中运行代码时,出现错误:

Trying to download a .m3u8 video file (http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8) using AVAssetDownloadURLSession. When i run the code in Xcode, I get an error:

错误域= AVFoundationErrorDomain代码= -11800 \"操作 无法完成\"UserInfo = {NSLocalizedFailureReason =未知 错误发生(-12780),NSLocalizedDescription =该操作可能 尚未完成}"

"Error Domain=AVFoundationErrorDomain Code=-11800 \"The operation could not be completed\" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed}"

.我使用的代码:

import UIKit
import AVFoundation

class ViewController: UIViewController, AVAssetDownloadDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.setupAssetDownload()
        // Do any additional setup after loading the view, typically from a nib.
    }


    func setupAssetDownload() {
        // Create new background session configuration.
        let configuration = URLSessionConfiguration.background(withIdentifier: "AssetID")

        // Create a new AVAssetDownloadURLSession with background configuration, delegate, and queue
        let downloadSession = AVAssetDownloadURLSession(configuration: configuration,
                                                        assetDownloadDelegate: self,
                                                        delegateQueue: OperationQueue.main)

        let url = URL(string: "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8")
        // let url = URL(string: "https://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8")
        let asset = AVURLAsset(url: url!)

        // Create new AVAssetDownloadTask for the desired asset
        let downloadTask = downloadSession.makeAssetDownloadTask(asset: asset,
                                                                 assetTitle: "AssetTitle",
                                                                 assetArtworkData: nil,
                                                                 options: nil)
        // Start task and begin download
        downloadTask?.resume()
    }

    //MARK: Delegates
    public func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didFinishDownloadingTo location: URL){
        print("DownloadedLocation:\(location.absoluteString)")
    }

    public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
        print("Error")
    }

    public func urlSession(_ session: URLSession, didBecomeInvalidWithError error: Error?) {
        print("Error")
    }

    public func urlSession(_ session: URLSession, taskIsWaitingForConnectivity task: URLSessionTask) {
        print("Waiting")
    }

    public func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) {
        print("Finihs collecting metrics:")
    }
}

与Github存储库的链接: https://github.com/dep2k/m3u8download.git

Link to Github repo: https://github.com/dep2k/m3u8download.git

推荐答案

我检查了您的代码,发现您没有将 NSAllowsArbitraryLoads 键添加到下的 YES 您的. plist文件

I checked your code and found that you missed to add NSAllowsArbitraryLoads key to YES under NSAppTransportSecurity dictionary in your .plist file

尝试并分享结果.

这篇关于尝试在iOS中使用AVAssetDownloadURLSession下载m3u8视频时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆