嵌入自动播放全屏视频的视频

时间:2014-03-15 21:18:28

标签: javascript html5 video youtube fullscreen

所以我要做的就是在我的网站上播放全屏视频。但我想自动播放youtube视频并自动播放全屏(浏览器窗口的大小)。我的网站导航是从页面到页面滑动的左右箭头。然后向上和向下滚动每页向上和向下滚动的箭头。

但我唯一想做的就是全屏播放youtube视频,同样是浏览器窗口的大小。或者我将不得不自己主持视频?这可能会更容易,但会占用我必须支付的带宽。无论如何,提前谢谢你的帮助,欢呼!

3 个答案:

答案 0 :(得分:17)

这里的答案很好:How to make a YouTube embedded video a full page width one?

如果你在嵌入代码的url末尾添加'?rel = 0& autoplay = 1'(就像这样)

<iframe id="video" src="//www.youtube.com/embed/5iiPC-VGFLU?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>
它应该在加载时播放的视频

。这是jsfiddle的演示。

答案 1 :(得分:0)

Chrome 不支持自动全屏,但您可以像这样简单地播放视频:

<iframe width="640" height="360" src="youryoutubeurlhere" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

答案 2 :(得分:0)

这将有助于autoplay视频加载并使其全屏显示,但由于 Chrome 自动播放政策,运行的视频必须静音。

// https://jsfiddle.net/jlam55555/o5njka95/6/

function requestFullScreen(element) {
    // Supports most browsers and their versions.
    var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullscreen;

    if (requestMethod) { // Native full screen.
        requestMethod.call(element);
    } else if (typeof window.ActiveXObject !== "undefined") { // Older IE.
        var wscript = new ActiveXObject("WScript.Shell");
        if (wscript !== null) {
            wscript.SendKeys("{F11}");
        }
    }
}
// FullScreen function
function makeFullScreen() {
    document.getElementsByTagName("iframe")[0].className = "fullScreen";
    var elem = document.body;
    requestFullScreen(elem);
}
iframe.fullScreen {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}
<body onload="makeFullScreen()">
<iframe src="https://www.youtube.com/embed/668nUCeBHyY?autoplay=1&mute=1&controls=0&rel=0" frameborder="0" allow="autoplay; picture-in-picture" title="YouTube Embed"></iframe>
</body>