本文介绍了在youtube javascript api中禁用自动播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道在params和url中使用自动播放:0。问题是当我使用loadVideoByID()函数时。最初的视频似乎总是不会自动启动。但是当我在新视频中加载新的自动启动时。我不希望新的自动启动
I know about using autoplay : 0 in params and in url. The problem is when I use the loadVideoByID() function. THe initial video seems to always not autostart. but the moment I load in new video that new one autostarts. I dont want that new one to autostart either
$(document).ready(function() {
var player;
window.onYouTubePlayerAPIReady = function() {
player = new YT.Player('player', {
height : '390',
width : '640',
videoId : 'JW5meKfy3fY',
playerVars : {
'autoplay' : 0,
'rel' : 0,
'showinfo' : 0,
'egm' : 0,
'showsearch' : 0,
'controls' : 0,
'modestbranding' : 1,
},
events : {
'onReady' : onPlayerReady,
'onStateChange' : onPlayerStateChange
}
});
};
window.onPlayerReady = function(event) {
//event.target.playVideo();
loadNewVid("bHQqvYy5KYo");
};
window.onPlayerStateChange = function(event, element) {
//When the video has ended
if (event.data == YT.PlayerState.ENDED) {
//Get rid of the player
element.style.display = "none";
}
};
function loadNewVid(vidID){
player.loadVideoById(vidID, "large");
}
});
推荐答案
根据定义, loadVideoById()
加载并播放视频。您想要使用的是 cueVideoById()
,它将准备它但等待命令实际播放。
By definition, loadVideoById()
loads AND plays the video. What you want to use is cueVideoById()
, which will prepare it but wait for a command to actually play.
这篇关于在youtube javascript api中禁用自动播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!