用于HTTPS的AVPlayer URL自定义加载 [英] AVPlayer URL custom loading for HTTPS
问题描述
我正在尝试使用AVPlayer
进行自定义URL加载(自定义NSURLProtocol
子类).但是[NSURLProtocol registerClass]
似乎无法在实际设备中与AVPlayer一起使用(请参阅
I'm trying to use AVPlayer
with custom URL loading (a custom NSURLProtocol
subclass). But it seems [NSURLProtocol registerClass]
does not work with AVPlayer in real device (see this thread).
现在,我正在尝试使用AVAssetResourceLoaderDelegate
进行自定义URL加载.但是,这对我来说有点令人困惑,将如何触发该委托.我处理的URL看起来像这样的https://some_ip_address:port/resource/
,但似乎没有为此类URL调用我的委托人.我试图将方案更改为非HTTP(例如"quic"),并能够触发委托代码,但我真的不想破解该方案.
Now I'm trying to use AVAssetResourceLoaderDelegate
to do the custom URL loading. However it is a bit confusing to me how the delegate will be triggered. The URL I deal with looks like this https://some_ip_address:port/resource/
, but it seems like my delegate is not called for such URL. I tried to change the scheme to non-HTTP (e.g. "quic") and was able to trigger the delegate code but I really don't want to hack the scheme.
这是相关代码:
(委托是在其他文件中实现的)
(delegate is implemented in a different file)
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
AVAssetResourceLoader *resourceLoader = asset.resourceLoader;
[resourceLoader setDelegate:delegate
queue:dispatch_queue_create("MyURLDelegate loader", nil)];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
controller.player = player;
[player play];
[self presentViewController:controller animated:false completion:^{}];
使用上述方法,如果url的方案为"https",则无法在委托中触发任何方法.我缺少允许委托为"https" URL进行自定义URL加载的内容吗?
With the above, I cannot see any methods are triggered in the delegate if url has the scheme of "https". What am I missing to allow the delegate to do custom URL loading for "https" URLs ?
谢谢
推荐答案
在我现在解决问题时,只需给出一个答案即可.简而言之,如果URL的方案为"http"或"https",则AVPlayer
和AVAssetResourceLoader
会忽略委托.
Just to follow up with an answer as I solved the problem now. Simply put, AVPlayer
and AVAssetResourceLoader
ignores the delegate if the URL has scheme of "http" or "https".
是的,解决方法是将URL方案替换为某些自定义方案,并在获取数据时将其替换回委托回调中.
Yes, the workaround is to replace the URL scheme with some custom scheme, and replace it back inside the delegate callback when fetching data.
- (BOOL) resourceLoader:(AVAssetResourceLoader *)resourceLoader
shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest
URL字符串为loadingRequest.request.URL.absoluteString
这篇关于用于HTTPS的AVPlayer URL自定义加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!