AVPlayer在播放HLS / AES加密视频之前发出无关的http请求 [英] AVPlayer making extraneous http request prior to playback of HLS / AES-encrypted video

查看:1264
本文介绍了AVPlayer在播放HLS / AES加密视频之前发出无关的http请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在iOS 8.4上使用AVPlayer播放HLS,AES加密视频。

We're using AVPlayer on iOS 8.4 to play HLS, AES-encrypted video.

我们的.m3u8文件包​​含许可证服务器的URL,例如:

Our .m3u8 files include the url of the license server, e.g.:

在我们的iOS应用程序中,我们使用AVAssetResourceLoaderDelegate方法
resourceLoader:shouldWaitForLoadingOfRequestedResource:
拦截AVPlayer(或AVFoundation中的某个对象)发送到许可证服务器的请求。在该方法中,我们将一个令牌(许可证服务器所需)添加到请求的queryString。

In our iOS application, we're using AVAssetResourceLoaderDelegate method resourceLoader:shouldWaitForLoadingOfRequestedResource: to intercept the request that gets sent by the AVPlayer (or some object within AVFoundation) to the license server. Within that method, we add a token (required by the license server) to the request's queryString.

许可证服务器接收带有令牌的请求,返回加密密钥,并开始播放。
换句话说,一切都按预期工作。

The license server receives the request with the token, returns the encryption key, and playback begins. In other words, everything works as expected.

然而,我们注意到(使用Charleshttp监视器)在创建AVPlayerItem之后,在调用resourceLoader:方法之前,AVFoundation 向许可服务器URL发送初始请求;未通过方法resourceLoader。此请求在服务器上被拒绝,因为我们的iOS代码在请求发出之前从未有机会附加令牌。

However, we're noticing (using the "Charles" http monitor) that following the creation of the AVPlayerItem and prior to the invocation of the resourceLoader: method, AVFoundation sends an initial request to the license server url; a request that's not "routed" through method resourceLoader:. This request is rejected at the server as our iOS code never has a chance to append the token before the request goes out.

事件摘要:

•AVPlayerItem / AVAsset是使用.m3u8索引文件的url创建和初始化的。

• AVPlayerItem/AVAsset is created and initialized with the url of the .m3u8 index file.

•AVFoundation框架中的某些内容使得请求到.m3u8文件中指定的许可证服务器。此初始请求不会被方法recourceLoader拦截:shouldWaitForLoadingOfRequestedResource:,并且未修改的请求会到达许可证服务器。因为请求在queryString中不包含必需的令牌,所以它失败并且不返回加密密钥。

• Something within the AVFoundation framwork makes a request to the license server specified in the .m3u8 file. This initial request is NOT intercepted by method  recourceLoader:shouldWaitForLoadingOfRequestedResource: and the unmodified request hits the license server.  Because the request doesn't contain a required token in the queryString, it fails and no encrypton key is returned.

AVFoundation发出第二个请求到licesnse服务器。此请求由recourceLoader捕获:...并进行适当修改。许可证服务器返回加密密钥并开始播放。

A second request is made by AVFoundation to the licesnse server. This request IS caught by recourceLoader:...and modified appropriately. The license server returns an encryption key and playback begins.

可以使用Apple的AVARLDelegateDemo应用程序复制此行为。

This behavior can be replicated using Apple's AVARLDelegateDemo app.

问题:

AVFoundation发送的初始http请求是否正常?

Is the initial http request sent by AVFoundation normal?

如果是这样,为什么它是必要的,为什么不通过resourceLoader:方法路由?

If so, why is it necessary and why isn't it getting "routed" through the resourceLoader: method?

是否可以抑制初始请求或修改它之前它发送了吗?

Is it possible to suppress the initial request or modify it before it's sent?

谢谢!

推荐答案

简单回答这个问题是 AVAssetResourceLoaderDelegate 只会处理无法以正常方式处理的URL请求。

The simple answer to this issue is that the AVAssetResourceLoaderDelegate will only handle requests for URLs which cannot be processed in the normal way.

In在您的情况下,您的密钥的URL是普通的https:// URL,因此AVPlayer将尝试自己处理此请求。但是,如果没有令牌,您的服务器将拒绝此请求。因此, AVAssetResourceLoaderDelegate 然后会将请求传递给您的委托来处理它。

In your case, the URL for your key is a normal https:// URL, so the AVPlayer will try to process this request itself. Without the token though, this request is rejected by your server. Therefore, the AVAssetResourceLoaderDelegate will then pass the request to your delegate to handle it.

避免'无关'请求,修改您的播放列表,以便加密密钥URL具有无效的方案。使用像crypt这样的东西://而不是https:// ....

To avoid the 'extraneous' request, modify your playlist so that the encryption key URL has an invalid scheme. Use something like crypt://... instead of https://....

这样,你会在第一次尝试时收到资源加载器调用,并且你可以用https://替换crypt:// scheme并在正常方式自己发出请求之前添加你的令牌。

That way, you will receive the resource loader call on the first try, and you can replace the crypt:// scheme with https:// and add your token before making the request yourself in the normal way.

这就是 AVAssetResourceLoaderDelegate 工作,我很害怕。
查看Apple的示例应用程序以获取更多详细信息:
https: //developer.apple.com/library/ios/samplecode/sc1791/

It's just how AVAssetResourceLoaderDelegate works, I'm afraid. Check out Apple's sample app here for more details: https://developer.apple.com/library/ios/samplecode/sc1791/

这篇关于AVPlayer在播放HLS / AES加密视频之前发出无关的http请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆