检测并拦截UIWebView中的video播放

我想拦截一个UIWebView的点击,然后使用video的URL。 这怎么可能? 我发现一个有点类似的post,指出遇到了

webView:shouldStartLoadWithRequest:navigationType: 

代表。 我似乎无法得到这个代表的video加载的url。

我试图让代码在iOS8中工作

通过侦听AVPlayerItemBecameCurrentNotification通知来findURL的方式很AVPlayerItemBecameCurrentNotification 。 当UIWebView显示媒体播放器时触发此通知,并发送一个AVPlayerItem作为通知的对象。

例如:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemBecameCurrent:) name:@"AVPlayerItemBecameCurrentNotification" object:nil]; -(void)playerItemBecameCurrent:(NSNotification*)notification { AVPlayerItem *playerItem = [notification object]; if(playerItem == nil) return; // Break down the AVPlayerItem to get to the path AVURLAsset *asset = (AVURLAsset*)[playerItem asset]; NSURL *url = [asset URL]; NSString *path = [url absoluteString]; } 

这适用于任何video(和audio)。 然而,媒体播放器加载后,这是不值得的,所以你不能阻止玩家在这个时候启动(如果这是你的意图)。

如果上述解决scheme不适用于任何人,那么请尝试侦听AVPlayerItemNewAccessLogEntry而不是AVPlayerItemBecameCurrentNotification。 似乎之后调用AVPlayerItemNewAccessLogEntry是我能够设置信息的地方。