2015-06-06 38 views
2

我只是想設置爲youtube API默認允許全屏,但我找不到,我是新的JavaScript我試過這麼多的代碼,但我沒有得到。其實我想允許全屏多個YouTube視頻。如何獲得全屏的YouTube的API

這裏是我工作

<div id="player"></div> 
<script src="http://www.youtube.com/iframe_api"></script> 

<script> 
    /** 
    * Put your video IDs in this array 
    */ 
    var videoIDs = [ 
     'MCgODvsmrmY', 
     'RdyXFNgZdCw' 
    ]; 

    var player, currentVideoId = 0; 


    function onYouTubeIframeAPIReady() { 
     player = new YT.Player('player', { 
      height: '350', 
      width: '425', 
      events: { 
       'onReady': onPlayerReady, 
       'onStateChange': onPlayerStateChange 
      } 
     }); 
    } 

    function onPlayerReady(event) { 
     event.target.loadVideoById(videoIDs[currentVideoId]); 
     node.requestFullScreen(); 

document.fullScreen; 

    } 

    function onPlayerStateChange(event) { 
     if (event.data == YT.PlayerState.ENDED) { 
      currentVideoId++; 
      if (currentVideoId < videoIDs.length) { 
       player.loadVideoById(videoIDs[currentVideoId]); 
      } 
     } 
    } 
</script> 

<script> 
window.onload = function(){ 
    document.getElementsByClassName("ytp-button-fullscreen-enter").click(); 
} 

</script> 

問候 馬頭

回答

0

我會在document.fullScreen行工作的代碼。

fullscreen demo從大衛沃爾什(他的好)使用下面的代碼:

// Find the right method, call on correct element 
function launchIntoFullscreen(element) { 
    if(element.requestFullscreen) { 
    element.requestFullscreen(); 
    } else if(element.mozRequestFullScreen) { 
    element.mozRequestFullScreen(); 
    } else if(element.webkitRequestFullscreen) { 
    element.webkitRequestFullscreen(); 
    } else if(element.msRequestFullscreen) { 
    element.msRequestFullscreen(); 
    } 
} 

// Launch fullscreen for browsers that support it! 
launchIntoFullscreen(document.documentElement); // the whole page 
launchIntoFullscreen(document.getElementById("videoElement")); // any individual element 
+0

想要保留這些代碼在我的代碼和它應該默認以全屏打開我的YouTube視頻? – madu

+0

我將有一個新的單擊事件處理程序,並將來自David的全屏代碼放在此處。 '$(「。fullscreen-button」)。click(function(){launchInto ...})'這樣做的原因是,通常瀏覽器不允許全屏啓動,而不被包裝在點擊事件中。這是因爲如果用戶可以控制全屏,瀏覽器供應商會覺得最好。 – bjfletcher

0

如果你想視頻的全屏幕任你從嵌入的視頻計算或高度和寬度計算視頻的比例。

注:新的寬度將保持不變

Example: if a video width = 300 and height = 270. 
Ratio = width/height. 
Say, your constant width_new = 200 
height_new = width_new/Ratio