Embedded YouTube video in WebView does not respect

2019-02-25 12:28发布

问题:

I am using the the guide displayed over here to embed a video in a WebView controller.

The WebView is inside an Activity which has the the theme Theme.Dialog

The embedded video is shown with the thumbnail first in a Activity. I use fs=0 to disable the fullscreen option.

After pressing the play button, the video loads in HTML5 mode (I think) and then it does not respect the fullsceen setting I've set.

How can I disable the full screen setting in the HTML5 mode?

My HTML code is as follows.

public String getHTML() {
        String html = "<iframe class=\"youtube-player\" style=\"border: 0; width: 100%; height: 95%; padding:0px; margin:0px\" id=\"ytplayer\" type=\"text/html\" src=\"http://www.youtube.com/embed/"
                + "k8GzqXg2ugA"
                + "?fs=0\" frameborder=\"0\">\n"
                + "</iframe>\n";
        return html;
    }

回答1:

You need to create a new WebChromeClient, overriding onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) and onHideCustomView()

See the following answer:

https://stackoverflow.com/a/12850816/475472