如何将自定义HTTP标头添加到AVAssetResourceLoaderDelegate加载请求
问题描述:
我需要在加载AVURLAsset
时从AVAssetResourceLoaderDelegate
的resourceLoader(:shouldWaitForLoadingOfRequestedResource:)
加载自定义HTTP标头到媒体加载请求。如何将自定义HTTP标头添加到AVAssetResourceLoaderDelegate加载请求
AVAssetResourceLoadingRequest
的request
是一个不可变属性,因此不可能调用addValue(...)
。
AVAssetResourceLoadingRequest
上有redirect
请求属性,它理论上可以用作原始请求加必要的标题,但它似乎没有任何效果(即所做的请求没有自定义标题)。
编辑:正如我所怀疑的那样,调用loadingRequest.request
后调用resourceLoader(:shouldWaitForLoadingOfRequestedResource:)
回调。
编辑2:那么AVURLAsset
确实有AVURLAssetHTTPCookiesKey
选项键,它可以让一个添加自定义的cookie,而不是任意的HTTP头,它似乎。
答
在你执行resourceLoader(:shouldWaitForLoadingOfRequestedResource:)
方法,你应该有类似下面的代码:
// somehow create the URLRequest that you need with the correct headers
let redirectRequest: URLRequest
loadingRequest.redirect = redirectRequest
loadingRequest.finishLoading
// tell the resource loader that you know how it should handle the request
return true
这是一种奇怪的界面和文档可以更清晰,但我认为这基本上是你所需要的。
戴夫,谢谢你的回答。最终我们决定使用嵌入式代理服务器,如下所述 - https://github.com/kevinjameshunt/AVPlayer-HTTP-Headers-Example –