And*_* Ho 4 objective-c video-streaming uiwebview ios uiwebviewdelegate
我想拦截UIWebView中的单击,然后使用视频的URL.这怎么可能?我发现了一个有点类似的帖子,它指向了
webView:shouldStartLoadWithRequest:navigationType:
Run Code Online (Sandbox Code Playgroud)
代表.我似乎无法通过此委托获取视频的加载网址.
我试图让代码在iOS8中运行
有一种通过监听AVPlayerItemBecameCurrentNotification通知来查找URL的hacky方法.当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];
}
Run Code Online (Sandbox Code Playgroud)
这适用于任何视频(和音频).然而,在媒体播放器加载后触发此功能并不值得,因此您无法阻止播放器在此时启动(如果这是您的意图).
| 归档时间: |
|
| 查看次数: |
3498 次 |
| 最近记录: |