在我的某个页面中我遇到了这种情况:
<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>
&#13;
<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>
&#13;
&#39>玩家&#39; div是youtube嵌入视频api javascript的目标。 我的问题是选项&#39;循环&#39;不适合我的工作 视频。
我的错误在哪里? 我应该选择什么选项?
提前致谢所有帮助
答案 0 :(得分:0)
使用此:
function onPlayerStateChange(event) {
if (event.data != YT.PlayerState.PLAYING ) {
player.playVideo();
}
}
使用!=
(不等于)代替==
(等于)