如何在UIWebview中获取当前播放视频的网址 [英] How to get the url of currently playing video in UIWebview

查看:219
本文介绍了如何在UIWebview中获取当前播放视频的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法获取当前播放视频的链接。我正在加载 m.youtube.com 。对于某些视频,它甚至没有进入代表。我也尝试过使用NStimer。但对于某些视频来说,它不是点击的网址

Is there any way to get the link of currently playing video.I am loading m.youtube.com .For some videos it is not even entering the delegates.I tried using a NStimer as well.But for some videos it is not the clicked url

推荐答案

有一种hacky方式它通过侦听 AVPlayerItemBecameCurrentNotification 通知。当UIWebView显示媒体播放器时会触发此通知,并且它会发送 AVPlayerItem 作为通知的对象。

There is a hacky way of doing it by listening for the AVPlayerItemBecameCurrentNotification notification. This notification is fired when a UIWebView shows the media player, and it sends an AVPlayerItem as the notification's object.

例如:

[[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];
}

这适用于任何视频(和音频)。但是,我注意到你提到了YouTube - 如果它能够下载YouTube视频全部,那么值得指出Apple WILL 拒绝你的应用,因为它反对YouTube的服务条款

This works for any video (and audio). However, I noticed you mentioned YouTube - it's worth pointing out Apple WILL reject your app if it has the ability to download YouTube videos AT ALL, because it's against YouTube's Terms of Service.

这篇关于如何在UIWebview中获取当前播放视频的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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