2013-11-26 51 views
1

無法讓自動播放的Chromeless播放器正常工作。 https://developers.google.com/youtube/youtube_player_demoChromeless和自動播放無法正常工作

IFRAME示例:http://jsfiddle.net/BN6Sa/

<iframe width="720" height="405" src="//www.youtube.com/embed/M7lc1UVf-VE?feature=player_embedded&autoplay=1&controls=0&loop=1&modestbranding=1&rel=0&showinfo=0&theme=light" frameborder="0" allowfullscreen></iframe> 

JS例:http://jsfiddle.net/7DWTU/

<div id="ytplayer"></div> 

<script> 
    // Load the IFrame Player API code asynchronously. 
    var tag = document.createElement('script'); 
    tag.src = "https://www.youtube.com/player_api"; 
    var firstScriptTag = document.getElementsByTagName('script')[0]; 
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 

    // Replace the 'ytplayer' element with an <iframe> and 
    // YouTube player after the API code downloads. 
    var player; 
    function onYouTubePlayerAPIReady() { 
    player = new YT.Player('ytplayer', { 
    height: '405', 
    width: '720', 
    videoId: 'M7lc1UVf-VE', 
    autoplay:1, 
    controls:0, 
    loop:1, 
    rel:0, 
    showinfo:0, 
    theme:'light' 
    }); 
    } 
</script> 

回答

0

當使用的iFrame API我試圖將代碼直接從developers.google.com載文複製,任何是玩家對象參數的東西(也就是說,如果你想將玩家嵌入到iFrame而不是API中),你需要將其作爲URL參數添加et作爲playerVars參數對象的一部分,而不是作爲YT.Player參數的直接參數。具體而言,您的代碼應如下所示:

<div id="ytplayer"></div> 

<script> 
    // Load the IFrame Player API code asynchronously. 
    var tag = document.createElement('script'); 
    tag.src = "https://www.youtube.com/player_api"; 
    var firstScriptTag = document.getElementsByTagName('script')[0]; 
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 

    // Replace the 'ytplayer' element with an <iframe> and 
    // YouTube player after the API code downloads. 
    var player; 
    function onYouTubePlayerAPIReady() { 
    player = new YT.Player('ytplayer', { 
    height: '405', 
    width: '720', 
    videoId: 'M7lc1UVf-VE', 
    playerVars: { 
     autoplay:1, 
     controls:0, 
     loop:1, 
     rel:0, 
     showinfo:0, 
     theme:'light' 
     } 
    }); 
    } 
</script> 
相關問題