Javascript可以检测嵌入的Youtube视频何时结束? [英] Can Javascript detect when an embedded Youtube video has ended?
问题描述
我有一个包含视频的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&version=3&rel=0&controls=0&showinfo=0&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&version=3&rel=0&controls=0&showinfo=0&autoplay=1"
type="application/x-shockwave-flash" width="420" height="160"
allowscriptaccess="always" allowfullscreen="true"></embed></object></div>
推荐答案
以下是您要找的内容:
// 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屋!