如何检测 YouTube 视频何时播放完毕?
我正在一个有大量嵌入式 YouTube 视频的网站上工作,客户希望在视频停止播放时显示一个弹出窗口。
我查看了 youtube api,似乎有一种方法可以检测视频何时结束:
http ://code.google.com/apis/youtube/js_api_reference.html
但我无法像他们在该页面上提到的那样嵌入视频,因为这些视频都已在网站上(已手动添加了数千个)经过粘贴嵌入代码)。
有没有办法在不更改任何现有视频的情况下检测这些视频的结尾(使用 javascript)?
I am working on a site that has a ton of embedded youtube videos, the client wants to show a popup whenever a video stops splaying.
I looked at the youtube api and there seems to be a way to detect when a video ends:
http://code.google.com/apis/youtube/js_api_reference.html
but I can't embed the videos like they mentioned on that page since the videos are all already on the site (thousands that have been added manually by pasting embed code).
Is there a way to detect the ending of these videos without changing any of the existing videos (using javascript)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可以通过 youtube 播放器 API 来完成:
http://jsfiddle.net/7Gznb/
工作示例:
This can be done through the youtube player API:
http://jsfiddle.net/7Gznb/
Working example:
您可能想要做的是在所有页面上包含一个执行以下操作的脚本...
1. 找到 youtube-iframe :按标题的宽度和高度搜索它,或在其源中查找 www.youtube.com。你可以通过...来做到这一点
- 通过 for-in 循环遍历 window.frames,然后通过属性过滤
在当前页面的 iframe 中注入 jscript 添加 onYoutubePlayerReady 必须包含函数
http://shazwazza.com/post/Injecting-JavaScript-into-other -frames.aspx
添加事件监听器等..
希望这有帮助
What you may want to do is include a script on all pages that does the following ...
1. find the youtube-iframe : searching for it by width and height by title or by finding www.youtube.com in its source. You can do that by ...
- looping through the window.frames by a for-in loop and then filter out by the properties
inject jscript in the iframe of the current page adding the onYoutubePlayerReady must-include-function
http://shazwazza.com/post/Injecting-JavaScript-into-other-frames.aspx
Add the event listeners etc..
Hope this helps