首页 > 解决方案 > Swift AVAssetDownloadURLSession 不会启动

问题描述

let background = URLSessionConfiguration.background(withIdentifier: "AAPL-Identifier")

var assetDownloadURLSession = AVAssetDownloadURLSession(configuration: background, assetDownloadDelegate: self, delegateQueue: OperationQueue.main)

let urlAsset = AVURLAsset(url: URL(string: "https://bitmovin-a.akamaihd.net/content/MI201109210084_1/m3u8s-fmp4/f08e80da-bf1d-4e3d-8899-f0f6155f6efa_video_180_250000.m3u8")!)
guard let task = assetDownloadURLSession.aggregateAssetDownloadTask(with: urlAsset, mediaSelections: [urlAsset.preferredMediaSelection], assetTitle: "Testing", assetArtworkData: nil, options:[AVAssetDownloadTaskMinimumRequiredMediaBitrateKey: 265_000]) else { return }

task.resume()

func urlSession(_ session: URLSession, aggregateAssetDownloadTask: AVAggregateAssetDownloadTask, didLoad timeRange: CMTimeRange, totalTimeRangesLoaded loadedTimeRanges: [NSValue], timeRangeExpectedToLoad: CMTimeRange, for mediaSelection: AVMediaSelection) {
    print("start download")
}

我正在使用官方示例代码,它工作正常。

但是当我尝试创建我的新样本时, AVAssetDownloadDelegate 永远不会触发......

请帮忙,谢谢!

标签: swiftdownloadavfoundationm3u8urlsession

解决方案


推荐阅读