我一直试图在iOS中一起处理多个HLS音频文件。这些文件用密钥加密。我需要获取密钥并将其存储在本地以供离线使用。当我同时下载少量(2个或3个文件)文件时,它可以正常工作,但是如果我同时开始下载10-15个文件,其中大多数文件都会失败,并显示错误消息-
Error Domain = AVFoundationErrorDomain代码= -11800“该操作可能 未完成” UserInfo = {NSLocalizedFailureReason =未知错误 发生(-17377),NSLocalizedDescription =无法执行该操作 完成}
我也从NSURLErrorDomain
收到错误消息,但是很少见。
我用来获取供离线使用的密钥的方法的链接如下-
Playing Offline HLS with AES-128 encryption iOS
任何帮助将不胜感激。
类AudioDownloader {
var productKey: String
var downloadUrl: URL
var downloadSession: AVAssetDownloadURLSession?
var fakeDownloadUrl: URL?
var downloadTask: AVAssetDownloadTask?
func downloadAudio() {
if downloadSession == nil {
let configuration = URLSessionConfiguration.background(withIdentifier: self.productKey)
downloadSession = AVAssetDownloadURLSession(configuration: configuration, assetDownloadDelegate: self, delegateQueue: OperationQueue.main)
configuration.shouldUseExtendedBackgroundIdleMode = true
configuration.httpShouldSetCookies = true
configuration.httpShouldUsePipelining = false
configuration.allowsCellularAccess = true
configuration.isDiscretionary = true
}
self.fakeDownloadUrl = self.convertToScheme(url: self.downloadUrl, scheme: "fakehttp")
let asset = AVURLAsset(url: self.fakeDownloadUrl!)
let loader = asset.resourceLoader
loader.setDelegate(self, queue: DispatchQueue(label: "dispatch2"))
self.downloadTask = downloadSession?.makeAssetDownloadTask(asset: asset, assetTitle: "assetTitle \(self.productKey)", assetArtworkData: nil, options: nil)!
self.downloadTask?.taskDescription = self.productKey
self.downloadTask?.resume()
}
}