How to get the url of currently playing video in UIWebview(如何在 UIWebview 中获取当前正在播放的视频的 url)
问题描述
有什么方法可以获取当前播放视频的链接.我正在加载 m.youtube.com.对于某些视频,它甚至没有进入代表.我也尝试使用 NStimer.但对于某些视频,它不是点击的 url
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
推荐答案
通过监听 AVPlayerItemBecameCurrentNotification
通知有一个 hacky 方法.当 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 - 值得指出的是,如果 Apple 将拒绝您的应用,如果它能够完全下载 YouTube 视频,因为它违反 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 中获取当前正在播放的视频的 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 UIWebview 中获取当前正在播放的视频的 url
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01