我知道在参数和 url 中使用 autoplay : 0 。问题是当我使用 loadVideoByID() 函数时。初始视频似乎总是不会自动启动。但是当我加载新视频时,新视频会自动启动。我也不希望那个新的自动启动
$(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");
}
});