3

I am loading html page in asset folder to android webview, the html pages has video. But video not playing, Here i share the code.

   <!doctype html>
   <head>
   <title></title>
   <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
   <script type="text/javascript" charset="utf-8" src="video.js"></script> 
   <script>
    function en(){
video1.play();
   }
   </script>
   </head>
   <body>
   <div id="t2" width ="1024" height="768" style="background-     image:url(images/L6_P007.jpg); background-repeat:no-repeat;">
    <video id="video1" width="1024" height="768" poster="images/L6_P007.jpg" controls  autoplay onended="en();" >
    <source src="videos/L6_P007.mp4" type="video/mp4">
    <source src="videos/L6_P007.ogv" type="video/ogg">
    <source src="videos/L6_P007.webm" type="video/webm">

    </video>
    </div>
    </body>
    </html>

This is my java code

    WebView webview = (WebView) findViewById(R.id.webView1);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
    webview.loadUrl("file:///android_asset/videosamp/videosamp.html");
Deepa
  • 31
  • 1
  • 3

1 Answers1

2

this issue is discussed many times on SO. check the answers to similar question here get the VideoPlayer Plugin for android here.

The video player allows you to display videos from your PhoneGap application.

This command fires an Intent to have your devices video player show the video.

Adding the Plugin to your project Using this plugin requires Android PhoneGap.

To install the plugin, move www/video to your project's www folder and include a reference to it in your html file after phonegap.js.

Create a directory within your project called "src/com/phonegap/plugins/video" and move VideoPlayer.java into it.

In your res/xml/plugins.xml file add the following line:

<plugin name="VideoPlayer" value="com.phonegap.plugins.video.VideoPlayer"/>

Using the plugin The plugin creates the object window.plugins.videoPlayer. To use, call the play() method:

/** * Display an intent to play the video. * * @param url The url to play */ play(url) Sample use:

window.plugins.videoPlayer.play("http://path.to.my/video.mp4");
window.plugins.videoPlayer.play("file:///path/to/my/video.mp4");
window.plugins.videoPlayer.play("file:///android_asset/www/path/to/my/video.mp4");
window.plugins.videoPlayer.play("https://www.youtube.com/watch?v=en_sVVjWFKk");

Note: When playing video from the assets folder, the video is first copied to internal storage with MODE_WORLD_READABLE.

Community
  • 1
  • 1
Neji
  • 6,591
  • 5
  • 43
  • 66
  • i edited my questions, can u share how to use plugin to load html pages in android webview – Deepa Feb 08 '13 at 10:44
  • i have to load the html page in android webview, not in vidoe view – Deepa Feb 12 '13 at 10:36
  • please check the link that i have provided, video tag from html5 is not supported in android webview thats why we need to use this library. – Neji Feb 12 '13 at 20:52