Android Webview with an Embedded Youtube Video, Full Screen Button Freezes Video

Unable to Full Screen Youtube Video Inside Custom Webview

To achieve this you should:

  1. Implement showCustomView and hideCustomView methods of WebChromeClient.
  2. Set android:hardwareAccelerated="true" to your MainActivity in AndroidManifest.xml.

There are two classes that inherit the WebChromeClient in your code (myWebChromeClient and MyWebChromeClient). The first implements showCustomView and hideCustomView methods and it seems fully working with full-screen video. The second one don't. But you (accidentally?) set the second as WebChromeClient to your WebView.

To fix this just change the line

webView.setWebChromeClient(new MyWebChromeClient());

to

mWebChromeClient = new myWebChromeClient();
webView.setWebChromeClient(mWebChromeClient);

in your initWebView() method.

UPD:

To lock orientation on portrait in normal (not full-screen) mode add following line into onHideCustomView() method:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

To let the system decide the best orientation in full-screen mode add this line to onShowCustomView(View view, CustomViewCallback callback) method:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);

Full screen option not available when loading YouTube video in WebView

iFrame is an option but you can try this

Android's WebView and WebChromeClient class extensions that enable
fully working HTML5 video support

VideoEnabledWebView

I have not try this yet but hope will help to you.

BadTokenException when trying to display fullscreen HTML5 video

I figured it out. The webview was inside of a pager. The previous developer was passing the application context to the pager instead of the activity context and I didn't realize it. Switching it over to the activity context fixed the problem.



Related Topics



Leave a reply



Submit