Can't fullscreen html5 videos in chrome's webview

前端 未结 2 1529
梦如初夏
梦如初夏 2020-12-22 08:55

I\'ve been searching around for this answer for a while but I\'m not really getting anywhere. My question is regarding a webview inside of a chrome application on a computer

相关标签:
2条回答
  • 2020-12-22 09:44

    It supports html5 fullscreen from version 43, you can use fullscreen permission API: See event-permissionrequest and FullscreenPermissionRequest. Basically, you have to "allow()" the permission, sth like:

    webview.addEventListener('permissionrequest', function(e) {
      if (e.permission === 'fullscreen') {
        e.request.allow();
      }
    });

    0 讨论(0)
  • 2020-12-22 09:51

    In addition to lazyboy's answer of setting the fullscreen permission and allowing it by:

    webview.addEventListener('permissionrequest', function(e) {
        if (e.permission === 'fullscreen') {
        e.request.allow();
        }
    });
    

    It might also be needed to set the webview dimensions itself to the screen dimensions as sometimes the HTML5 video might get fullscreened inside the webview only (and not the screen). This can be done as:

    document.addEventListener('webkitfullscreenchange', function(){
    if (chrome.app.window.current().isFullscreen()){
        webview.style.height = screen.height + 'px';
        webview.style.width = screen.width + 'px';
    }
    else{
       /*get webview to original dimensions*/
    };
    });
    

    webkitfullscreenchange listens to changes in fullscreen. If chrome window is fullscreen chrome.app.window.current().isFullscreen(), it sets the webview width and height to screen width and height respectively. If the window is not fullscreen, webview dimensions can be returned to desired.

    0 讨论(0)
提交回复
热议问题