我想拦截 UIWebView 中的点击,然后使用视频的 URL。这怎么可能?我发现了一个有点类似的帖子,它指出了
webView:shouldStartLoadWithRequest:navigationType:
代表。我似乎无法通过该委托获取视频的加载网址。
我正在尝试让代码在 iOS8 中运行
有一种通过侦听来查找 URL 的巧妙方法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];
}
这适用于任何视频(和音频)。然而,这是在媒体播放器加载后触发的,因此您无法阻止播放器在此时启动(如果这是您的意图)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)