Enabling Html5 Video Playback In Android Webview?
Solution 1:
I know from a previous project we did that you need to use the WebChromeClient
to get HTML5 video to play. (And this also gives you hardware accelerated support too - providing you also set the flags on your activity).
Use:
mainWebView.setWebChromeClient(newWebChromeClient());
Put that before you set the setWebViewClient. You can override the WebChromeClient to intercept any events you need to handle.
And in your AndroidManifest.xml within your activity definition, add:
android:hardwareAccelerated="true"
The following quote is from this SDK Page (scroll down to HTML5 Video support)
In order to support inline HTML5 video in your application, you need to have hardware acceleration turned on, and set a WebChromeClient.
Solution 2:
Given below html5 tag works for me without changing anything in android code
<videosrc="video/placeholder.m4v"poster="video/placeholder.jpg"onclick="this.play();"/>
You can check in detail here
Credit: irregular shed
Solution 3:
As far as I know android webview has Chromium engine and it does not support HTML 5 videos (H.264) in fullscreen mode. You can try playing video but video goes out of the screen and its not consistence across all the devices. If webview is the main part of the app then its better to switch to mozilla geckoview but it will add 30 to 40 mb to your apk.
Solution 4:
I got success to show video using html5 video tag using the following code:
mainWebView.setWebChromeClient(new WebChromeClient());
android:hardwareAccelerated="true"
Post a Comment for "Enabling Html5 Video Playback In Android Webview?"