【发布时间】:2018-05-08 20:10:56
【问题描述】:
我正在使用 AVAssetResourceLoadingDelegate 拦截 HLS 清单的所有清单请求
let str = "examplehttp://example.com/path/to/master.m3u8?token=SOMETOKEN"
guard let url = URL(string: str) else { return }
let asset = AVURLAsset(url: url)
let loaderQueue = DispatchQueue(label: "com.example.LoaderQueue")
asset.resourceLoader.setDelegate(delegate, queue: loaderQueue)
let item = AVPlayerItem(asset: asset)
player = AVPlayer(playerItem: item)
player?.playImmediately(atRate: 1.0)
在委托中,我自己使用URLSession 执行所有清单请求,并将响应返回给AVAssetResourceLoadingRequest
// NOTE: dataRequest: AVAssetResourceLoadingDataRequest
dataRequest.respond(with: data)
loadingRequest.response = response
loadingRequest.finishLoading()
此流使用相当标准的身份验证过程进行保护:
对主清单的请求是使用附加的令牌查询参数进行的。对主清单的响应包括一个 set-cookie 标头。在 set-cookie 响应标头中指定域的每个后续请求都在其请求标头中包含 cookie。
我发现所有通过委托发出的请求都将 cookie 添加到标头中,但由于委托不能用于 TS 段,因此没有添加 cookie。
有谁知道强制AVURLAsset 始终使用主清单响应提供的cookie 标头来处理AVAssetResourceLoaderDelegate 之外发出的请求的方法?
由于我确实将URLResponse 提供回AVAssetResourceLoadingRequest,并且我知道您可以使用URLSessionConfiguration 的httpShouldAccpetCookies、httpCookieAcceptPolicy 和httpCookieStorage 属性将cookie 添加到URLSession。我不认为这超出了可能性范围。
我也知道AVURLAssetHTTPCookiesKey 可以添加到AVURLAasset 的实例化中,但在发出主清单请求之前我没有cookie。
【问题讨论】:
-
在此期间您有没有发现任何新的东西?或者你是怎么解决的?现在面临同样的问题。
-
除了下面的答案之外没有什么新鲜事。我们必须请求 cdn 来支持分段请求中的查询令牌。
标签: swift avfoundation http-live-streaming avassetresourceloaderdelegate