Unable to Full Screen Youtube Video Inside Custom Webview
To achieve this you should:
- Implement
showCustomView
andhideCustomView
methods ofWebChromeClient
. - Set
android:hardwareAccelerated="true"
to yourMainActivity
inAndroidManifest.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
How to Send and Receive Data Sms Messages
What Is the Real Android Studio Gradle Version
Display Fragment Viewpager Within a Fragment
Kill Another Application on Android
How to Implement Filterable in Realmrecyclerviewadapter
Programmatically Update Widget from Activity/Service/Receiver
How to Use Icons and Symbols from "Font Awesome" on Native Android Application
Android Viewpager with Bottom Dots
How Does the Mapping Between Android Resources and Resources Id Work
Android - Webview Language Changes Abruptly on Android 7.0 and Above
How to Get the Correct Orientation of the Image Selected from the Default Image Gallery
Use a Custom Contextual Action Bar for Webview Text Selection
Android M Permissions:Confused on the Usage of Shouldshowrequestpermissionrationale() Function
Install_Failed_Update_Incompatible When I Try to Install Compiled .Apk on Device