Show HTML5 Video Fullscreen

后端 未结 2 900
悲&欢浪女
悲&欢浪女 2021-02-09 19:36

I have a webview that has html video inside it. I want to show this video fullscreen so I override onShowCustomView of my WebChromeClient to use a

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-09 20:20

    This works for me.

    I found a 'quirks solution' in making the web app with vimeo videos. I tested two devices. One is Android 4.2.x version, another is 4.4.x version. One is able to play video in fullscreen mode, another is not able to.

    After reading official document 'Migrating to WebView in Android 4.4', I found that there are different 'UserAgent' names in two devices.

    One has this userAgent.

    Mozilla/5.0 (Linux; Android 4.4.2; SHV-E300L Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36
    

    Another has this.

    Mozilla/5.0 (Linux; Android 4.4.4; SHV-E370K Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36
    

    I think the chrome version is the solution making fullscreen video. So I changed the chrome version to 30.x.

    WebSettings s = mWebView.getSettings();
    //Change UserAgent to play fullscreen vimeo's videos.
    String agent = s.getUserAgentString();
    String p = "(Chrome/[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)";
    Pattern pattern = Pattern.compile(p);
    Matcher matcher = pattern.matcher(agent);
    if(matcher.find()) {
        agent = matcher.replaceFirst("Chrome/30.0.0.0");
    }
    s.setUserAgentString(agent);
    

    Oh~~ I can sleep... (sorry with my poor english)

提交回复
热议问题