Get html 5 video to automatically open in fullscreen mode

ぐ巨炮叔叔 提交于 2019-12-23 04:43:21

问题


I succeeded in getting a video to open in fullscreen mode in response to events (click, keypress) using the HTML 5 video tag and jQuery. How do I get the video to open in fullscreen on page load instead of onclick? Any help would be appreciated. Many thanks!

My HTML:

    <div id="video_container>
       <video id="video1" width="1280" height="720" controls autoplay>
          <source src="videos/ballet.mp4" type="video/mp4">
          <source src="videos/ballet.webm" type="video/webm">
          <source src="videos/ballet.ogv" type="video/ogg">
       </video>
    </div>

My JavaScript:

$(document).ready(function(){     
      $('#video1').bind("playing", function(){

        var elem = document.getElementById("video1");
        if (elem.requestFullscreen) {
          elem.requestFullscreen();
        } else if (elem.mozRequestFullScreen) {
          elem.mozRequestFullScreen();
        } else if (elem.webkitRequestFullscreen) {
          elem.webkitRequestFullscreen();
        }
      });

      $('#video1').bind("ended", function(){ 
        $("#video_container").hide();
      });
 });

回答1:


Sounds like you can't make the video fullscreen on page load, at least not for webkit browsers. According to the Safari Developer Library:

The webkitEnterFullscreen() method can be invoked only in response to a user action, such as clicking a button. You cannot invoke webkitEnterFullscreen() in response to a load event, for example.

Full article here: https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/ControllingMediaWithJavaScript/ControllingMediaWithJavaScript.html



来源:https://stackoverflow.com/questions/20257355/get-html-5-video-to-automatically-open-in-fullscreen-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!