Can't fullscreen html5 videos in chrome's webview

不问归期 提交于 2019-11-29 17:22:24

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();
  }
});

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.

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