I'm trying to play mp4 video in webView using HTML5 in android but unfortunately it's not working, So can anyone help me, how can i do it ?
Here is my code HTML file with name new2.html
<video width="365" height="200" src="/sdcard/Download/video.mp4" controls autobuffer></video>
<!--<!DOCTYPE html>
<html>
<body>
<video width="320" height="240" controls autoplay>
<source src="/sdcard/Download/video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</body>
</html>-->
Java file is:
public class WebActivity extends Activity {
WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.web_activity);
wv = (WebView) findViewById(R.id.webview);
wv.loadUrl("file:///android_asset/new2.html");
wv.getSettings().setAllowFileAccess(true);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginsEnabled(true);
// webview.loadUrl("file:///android_asset/new.html");
}
}
XML file is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
You need to call your file through local host -- file://localhost/ -- otherwise your phone will not recognize that it is you asking for permissions. By using your browser without localhost you are pinging off a satellite and can not make it back on re-rentry.
You are getting the controls to display because they come from a public html folder, but your source ( the video ) does not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With