How to play video in android web browser using html5

I used the code below to play a video in android WebView that contains a, I placed the video and poster image in the resource folder.

vWebview = (WebView)findViewById(R.id.VWebview); vWebview.getSettings().setJavaScriptEnabled(true); vWebview.getSettings().setPluginsEnabled(true); ViewContent(raw); InputStream fileStream = getResources().openRawResource(R.raw.test); int fileLen = fileStream.available(); byte[] fileBuffer = new byte[fileLen]; fileStream.read(fileBuffer); fileStream.close(); String displayText = new String(fileBuffer); vWebview.loadDataWithBaseURL("fake://not/needed", displayText, "text/html", "utf-8", ""); 

The html file is as follows:

 <!DOCTYPE HTML> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Hello World</title> <body> <div> <p> <video src="file:///android_asset/bigbuck.m4v" poster="file:///android_asset/test.jpg" onclick="this.play();"/> </p> </div> </body> </html> 

It is working fine. The poster image is displayed correctly, as soon as I click, it gives an error:

 05-12 10:24:22.207: ERROR/http(2882): Null or empty value for header "Host" 05-12 10:24:22.207: ERROR/webcoreglue(2882): *** Uncaught exception returned from Java call! 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): Uncaught handler: thread WebViewCoreThread exiting due to uncaught exception 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): java.lang.RuntimeException: Null or empty value for header "Host" 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): at android.net.http.Request.addHeader(Request.java:161) 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): at android.net.http.Request.<init>(Request.java:126) 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): at android.net.http.RequestQueue.queueRequest(RequestQueue.java:359) 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): at android.net.http.RequestQueue.queueRequest(RequestQueue.java:327) 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): at android.webkit.HTML5VideoViewProxy$PosterDownloader.start(HTML5VideoViewProxy.java:275) 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): at android.webkit.HTML5VideoViewProxy.loadPoster(HTML5VideoViewProxy.java:490) 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): at android.webkit.WebViewCore.nativeTouchUp(Native Method) 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): at android.webkit.WebViewCore.access$3400(WebViewCore.java:48) 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1095) 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): at android.os.Handler.dispatchMessage(Handler.java:99) 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): at android.os.Looper.loop(Looper.java:123) 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:612) 05-12 10:24:22.262: ERROR/AndroidRuntime(2882): at java.lang.Thread.run(Thread.java:1096) 
+4
source share
3 answers

I placed the video files in the RAW folder and got access to the video file in the default.html file using the following code:

  video.src ="android.resource://ProjectPackageAame/raw/bigbuck"; video.type = "video/mp4"; video.load(); video.play(); 

It plays the video as I want. Also added the following line in the AndroidManifest file.

  android:hardwareAccelerated="true" 

Try this where to place local video files for the html5 Android application for Android Android

+2
source

According to http://html5test.com/compare/browser/android40.html , Android 4.0 supports the video element, but it does not support embedding MP4, H.264 or Ogg video. I also tried to create an Android PhoneGap application with HTMl5 video and it does not play the video. HTML5 is valid, but Android browser cannot play video. Also, your HTML5 code seems to be wrong. The W3Schools website has installed HTML5 video tags as follows:

 <video width="width" height="height" poster="postersrc.jpg" controls="controls"> <source src="source.mp4" type="video/mp4" /> <source src="source.ogg" type="video/ogg" /> No support for HTML5 video. Sorry! </video> 

This really confuses how the browser can support the HTML5 video tag without supporting any type of video.

+1
source

Remove the src attribute from the video tag and make a javascript function to play the video.

0
source

All Articles