2017-02-23 132 views
2

我需要在加载AVURLAsset时从AVAssetResourceLoaderDelegateresourceLoader(:shouldWaitForLoadingOfRequestedResource:)加载自定义HTTP标头到媒体加载请求。如何将自定义HTTP标头添加到AVAssetResourceLoaderDelegate加载请求

AVAssetResourceLoadingRequestrequest是一个不可变属性,因此不可能调用addValue(...)

AVAssetResourceLoadingRequest上有redirect请求属性,它理论上可以用作原始请求加必要的标题,但它似乎没有任何效果(即所做的请求没有自定义标题)。

编辑:正如我所怀疑的那样,调用loadingRequest.request后调用resourceLoader(:shouldWaitForLoadingOfRequestedResource:)回调。

编辑2:那么AVURLAsset确实有AVURLAssetHTTPCookiesKey选项键,它可以让一个添加自定义的cookie,而不是任意的HTTP头,它似乎。

回答

1

在你执行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 

这是一种奇怪的界面和文档可以更清晰,但我认为这基本上是你所需要的。

+0

戴夫,谢谢你的回答。最终我们决定使用嵌入式代理服务器,如下所述 - https://github.com/kevinjameshunt/AVPlayer-HTTP-Headers-Example –

相关问题