我知道在params和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"); }
});@H_502_5@
解决方法
根据定义,loadVideoById()加载并播放视频.您要使用的是cueVideoById(),它将准备它,但等待命令实际播放.
https://developers.google.com/youtube/js_api_reference#cueVideoById@H_502_5@