gpt4 book ai didi

javascript - youtube视频结束时的事件

转载 作者:行者123 更新时间:2023-12-03 06:25:50 25 4
gpt4 key购买 nike

我有简单的HTML代码,点击图片后即可播放youtube视频。

<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<div id="ytapiplayer2" style="display:none;">
<object width="1280" height="745">
<param name="movie" value="http://www.youtube.com/v/kCfP003Btjw?fs=1&hl=en_US&rel=0&autoplay=1"></param>
<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/kCfP003Btjw?fs=1&hl=en_US&rel=0&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="1280" height="745"></embed>
</object>

</div>


<img src="https://i.qmyimage.com/mgen/global/zGetImageNew.ms?args=%22shpimg4198.jpg%22,425,96,1" id="imageID" />
<script type="text/javascript">
$('#imageID').click(function() {
$('#ytapiplayer2').show();
$('#imageID').hide();
});
</script>
</body>

视频播放完后,我需要隐藏视频并向后显示图像。如何实现?

最佳答案

Youtube具有JavaScript API:https://developers.google.com/youtube/js_api_reference

您需要的是onStateChange事件,该事件结束时将为您提供0。

player.addEventListener("onStateChange", function(state){
if(state === 0){
// the video is end, do something here.
}
});

关于javascript - youtube视频结束时的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26821733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com