我尝试了以下方法:
func setupAssetDownload() {
// Create new background session configuration.
let configuration = URLSessionConfiguration.background(withIdentifier: "123124123152")
// Create a new AVAssetDownloadURLSession with background configuration, delegate, and queue
let downloadSession = AVAssetDownloadURLSession(configuration: configuration,
assetDownloadDelegate: self,
delegateQueue: OperationQueue.main)
let url = URL(string: "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8")// HLS Asset URL
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
print(downloadTask.debugDescription)
downloadTask?.resume()
}
并实施
func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didFinishDownloadingTo location: URL) {
print("didFinishDownloadingTo \(location.relativePath)")
playOfflineAsset()
}
但是永远不会调用委托方法
didFinishDownloadingTo
。还添加了
didCompleteWithError
委托,但没有成功。我的班级符合
AVAssetDownloadDelegate
。 最佳答案
AVAssetDownloadURLSession始终只能在真实设备上使用。
请搭配Real device
关于swift - 无法弄清HLS下载,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51240658/