Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show HTML5 Video Fullscreen

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 VideoView. This works great in 2.3, however, in 4.x onShowCustomView is never called. The video will still play, however, it is played from within the webview without any controls besides clicking for play and stop.

Also, I have hardwareAccelerated="true".

Any idea why onShowCustomView is never 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");
    }

...
like image 406
Nick Avatar asked Sep 07 '12 14:09

Nick


People also ask

How do I view HTML5 video?

The webmasters need to use special HTML5 coding and include WebM, MP4 and OGG formats on their web pages. Before HTML5 videos were only played using the Flash Player. You can view HTML5 videos on all popular browsers such as Google Chrome, Internet Explorer, Mozilla Firefox, and Safari.

How do I force HTML full screen?

Full-screen can be activated for the whole browser window by pressing the F11 key. It can be exited by pressing the Esc button.


1 Answers

Well after struggling with this for a while, I finally found the cause. In Android 4.x you must show the controls by using the html 'controls' attribute in the 'video' tag. Once you are showing these controls, you can click on the fullscreen button which will then call 'onShowCustomView'. Since embedded video is available in 4.x and you have the option to go to fullscreen with the controls, onShowCustomView will not be called automatically on play. Unfortunately, this is very poorly documented in the Android documentation.

like image 149
Nick Avatar answered Nov 03 '22 23:11

Nick