gpt4 book ai didi

javascript - 嵌入iframe-YouTube视频不循环播放

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

在我的页面之一中,我遇到了这种情况:

<script>
/* 2. This code loads the IFrame Player API code asynchronously.
*/
var tag = document.createElement('script');

tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

/* 3. This function creates an <iframe> (and YouTube player) after the API code downloads.
*/
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
videoId: 'xbiEN3jGi00',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
},
playerVars: {
'autoplay': 1,
'loop': 1,
'controls': 0,
'rel' : 0,
'showinfo': 0,
}
});
}

/* 4. The API will call this function when the video player is ready.*/
function onPlayerReady(event) {
event.target.playVideo();
player.mute();
}

/* 5. The API calls this function when the player's state changes.
The function indicates that when playing a video (state=1),
The player should play for six seconds and then stop.
*/
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING ) {
player.playVideo();
}
}
</script>
<div class="video-background-container parallax embed-responsive embed-responsive-16by9" data-stellar-ratio="0.4">
<div id="player" class="embed-responsive-item"></div>
</div>


The 'player' div is the target of the youtube embed video api javascript. My problem is that the option 'loop' doesn't work for my video.



我的错误在哪里?
我应该设置什么选项?

预先感谢所有帮助

最佳答案

用这个:

function onPlayerStateChange(event) {
if (event.data != YT.PlayerState.PLAYING ) {
player.playVideo();
}
}

使用 !=(不等于)代替 ==(等于)

关于javascript - 嵌入iframe-YouTube视频不循环播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38207594/

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