Show HTML5 fullscreen

I have a webview that has html video in it. I want to show this full screen video in order to override onShowCustomViewmine WebChromeClientto use VideoView. This works fine in 2.3, however it onShowCustomViewnever gets called in 4.x. The video will still play, but it will play from the web view without any controls other than clicking to play and stop.

In addition, I have hardwareAccelerated = "true".

Any idea why it onShowCustomViewnever gets called?

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    webView = (WebView) findViewById(R.id.webView);

    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    webView.setWebViewClient(new WebViewClient());
    webView.setWebChromeClient(new MyChromeClient());

    webView.loadUrl(URL);

}

private class MyChromeClient extends WebChromeClient implements
        OnCompletionListener, OnErrorListener, OnPreparedListener {

    @Override
    public void onShowCustomView(View view, CustomViewCallback callback) {
        Log.d("ma", "onShowCustomView");
    }

...
+5
source share
2 answers

, . Android 4.x , html 'controls' 'video'. , , , "onShowCustomView". 4.x, , onShowCustomView . , Android.

+9

.

" quirks" - vimeo. . - Android 4.2.x, 4.4.x. , - .

"" WebView Android 4.4 " , " 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

.

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

, - - , . chrome 30.x.

WebSettings s = mWebView.getSettings();
//Change UserAgent to play fullscreen vimeo 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);

~~ ... ( )

0

All Articles