如何获得全屏的YouTube api



我只是试图设置默认允许全屏youtube api,但我找不到,我是新的javascript我尝试了很多代码,但我没有得到。实际上,我想让多个youtube视频与全屏。

这是我正在工作的代码

<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>

的问候但是

我将在document.fullScreen行工作。

这个来自David Walsh的全屏演示使用了以下代码:

// 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

如果你想要全屏视频,你可以从嵌入视频计算或计算视频的高度和宽度的比例。

注意:新的宽度将是恒定的

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

相关内容

  • 没有找到相关文章

最新更新