Javascript可以检测嵌入的Youtube视频何时结束? [英] Can Javascript detect when an embedded Youtube video has ended?

查看:96
本文介绍了Javascript可以检测嵌入的Youtube视频何时结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含视频的div。 div的背景是一个虚假的播放按钮,我将其设计为播放按钮,而不是Youtube的标准视频播放按钮。该视频最初设置为display:none。

I have a div containing a video. The background of the div features a fake "play" button, which I've designed to use as the play button instead of Youtube's standard video "play" button. The video is initially set to "display:none".

我已经部署了下面的代码,以便当您点击div时,div消失,视频现在消失显示并开始播放。

I've deployed the code below so that when you click on the div, the div disappears and the video now displays and begins to play.

如何编辑代码,以便在视频播放完毕后,视频消失并重新显示div?

How can I edit the code so that when the video has finished playing, the video disappears and the div re-appears?

<div  class="videodiv" this.style.cursor='pointer'; 
onclick="thevid=document.getElementById('thevideo'); thevid.style.display='block'; 
this.style.display='none'; "></div>
<div  class="youtubevid" id="thevideo" style="display: none;"><object width="420" 
height="160"><param name="movie" value="//www.youtube.com/v/vIdeoUrl?
 hl=en_US&amp;version=3&amp;rel=0&amp;controls=0&amp;showinfo=0&amp;autoplay=1">
</param><param name="allowFullScreen" value="true"></param><param 
name="allowscriptaccess" value="always">
</param><embed src="//www.youtube.com/v/vIdeoUrl?
hl=en_US&amp;version=3&amp;rel=0&amp;controls=0&amp;showinfo=0&amp;autoplay=1" 
type="application/x-shockwave-flash" width="420" height="160" 
allowscriptaccess="always" allowfullscreen="true"></embed></object></div>


推荐答案

以下是您要找的内容:

http://jsfiddle.net/7Gznb/

// when video ends
    function onPlayerStateChange(event) {        
        if(event.data === 0) {            
            alert('done');
          //do something here

        }

这就是Youtube顺便说一下API

That's the Youtube API by the way

这篇关于Javascript可以检测嵌入的Youtube视频何时结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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