在iPad / iPhone上使用HTML5视频全屏

时间:2022-08-26 19:00:35

I'm trying to play and go fullscreen for an HTML5 video element on an iPad/iPhone via JavaScript, but when I try videoElement.webkitEnterFullScreen(), I see an INVALID_STATE_ERR: Dom Exception 11.

我正在试图通过JavaScript在iPad / iPhone上全屏播放HTML5视频元素,但是当我尝试使用videoElement.webkitEnterFullScreen()时,我看到了一个INVALID_STATE_ERR:Dom Exception 11。

My Code

For Example

Now, it looks like specific support for this behavior was added here:

现在,看起来在这里添加了对此行为的特定支持:

which specifically prevents going fullscreen without a user gesture.

这特别阻止了没有用户手势的全屏。

My question:

Is there a workaround for this?

这有解决方法吗?

I see that Vimeo's HTML5 video player is mimicking this behavior somehow as seen here (on iPad/iPhone)

我看到Vimeo的HTML5视频播放器模仿了这种行为,就像在这里看到的那样(在iPad / iPhone上)

So, it seems it is possible. Am I missing something?

所以,似乎有可能。我错过了什么吗?

2 个解决方案

#1


5  

Testing on iOS simulator Ipad

在iOS模拟器Ipad上测试

Hope I can help someone:

希望我能帮助别人:

<html>
<head>
 <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
 <script type="text/javascript">
    var vid;

    function init() {
        vid = document.getElementById("myVideo");
        vid.addEventListener("loadedmetadata", goFullscreen, false); 
    }

    function goFullscreen() {
        vid.webkitEnterFullscreen();
    }

    $(document).ready(function(){
        init();

        $("#myVideo").bind('ended', function(){
            $('#myVideo')[0].webkitExitFullScreen();
        });
    });
 </script>
</head>
<body>
    <h1>Fullscreen Video</h1>
    <video src="movie.mp4" id="myVideo" autoplay controls >
    </video>
</body>
</html>

#2


0  

I used this and it worked for me

我用过这个,它对我有用

- (void) makeHTML5VideoFullscreen {
    if(webView) {
        [webView stringByEvaluatingJavaScriptFromString: @"document.querySelector('video').webkitEnterFullscreen();"];
    }
}

#1


5  

Testing on iOS simulator Ipad

在iOS模拟器Ipad上测试

Hope I can help someone:

希望我能帮助别人:

<html>
<head>
 <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
 <script type="text/javascript">
    var vid;

    function init() {
        vid = document.getElementById("myVideo");
        vid.addEventListener("loadedmetadata", goFullscreen, false); 
    }

    function goFullscreen() {
        vid.webkitEnterFullscreen();
    }

    $(document).ready(function(){
        init();

        $("#myVideo").bind('ended', function(){
            $('#myVideo')[0].webkitExitFullScreen();
        });
    });
 </script>
</head>
<body>
    <h1>Fullscreen Video</h1>
    <video src="movie.mp4" id="myVideo" autoplay controls >
    </video>
</body>
</html>

#2


0  

I used this and it worked for me

我用过这个,它对我有用

- (void) makeHTML5VideoFullscreen {
    if(webView) {
        [webView stringByEvaluatingJavaScriptFromString: @"document.querySelector('video').webkitEnterFullscreen();"];
    }
}