Webview HTML Video fullscreen - onShowCustomView() called only once

2.8k Views Asked by At

I am using HTML video tag to play video in android Webview. However, when I try to press the fullscreen button, the onShowCustomView() from webview chrome client is called only the first time. Every subsequent time I press the fullscreen button, the function onShowCustomView() is not called.

What I want is, every time I press the fullscreen button, onShowCustomView() should be called.

Webview

webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    webView.getSettings().setAppCacheEnabled(true);
    webView.setWebChromeClient(mClient);
    webView.setWebViewClient(new WebViewClient());

HTML Video Tag

<div>
       <!--<img id="videoImage" src="img/UI_homepage_innovation.png" style="cursor:pointer" onclick="play()"/>
       <iframe id="video" style="display:none;" src="http://www.youtube.com/embed/SNMjzPRQUA8?modestbranding=1&rel=0&showinfo=0&autohide=1&fs=0&autoplay=1"  frameborder="0" #allowfullscreen></iframe>-->
       <video poster="img/UI_homepage_innovation.png" controls>
           <source src="video/sintel.mp4" type="video/mp4">
                Your browser does not support the video tag.
       </video>
</div>

Webview Chrome Client

public class MyChromeClient extends WebChromeClient {

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

    @Override
    public void onHideCustomView() {
        Log.v("Testing", "onHideCustomView");
    }
}
1

There are 1 best solutions below

0
On BEST ANSWER

In order for this to work correctly, I learned that I needed to get the video view Holder and put it in another view. However, I wanted to use my own custom fullscreen view.

In order to do that I made my own custom HTML video controls for using CSS and Javascript and used a 'fullscreen' button to call my custom fullscreen view everytime. Worked like a charm!