Deepa
Deepa

Reputation: 31

Video not playing in android webview

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");

Upvotes: 3

Views: 6463

Answers (1)

Neji
Neji

Reputation: 6839

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.

Upvotes: 2

Related Questions