我一直在尝试在 iOS 中将多个 HLS 音频文件放在一起。文件使用密钥加密。我需要获取密钥并将其存储在本地以供离线使用。当我同时下载少量(2 或 3 个文件)文件时,它工作正常,但如果我同时开始下载 10-15 个文件,其中大多数文件都会失败并显示错误消息 -
错误域=AVFoundationErrorDomain Code=-11800 "操作无法完成" UserInfo={NSLocalizedFailureReason=发生未知错误 (-17377), NSLocalizedDescription=操作无法完成}
我也收到了错误消息,NSURLErrorDomain
但它们很少见。我用来获取离线使用密钥的方法的链接如下 -
任何帮助,将不胜感激。
类音频下载器 {
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()
}
}