how to play video using html5 videoplayer in android phonegap?

こ雲淡風輕ζ 提交于 2019-12-12 03:19:36

问题


I have created application in android phonegap.I want to play video using html5 video player. My code is:

<!DOCTYPE html>
    <html>
        <head>
          <title>Video.js | HTML5 Video Player</title>
          <link href="http://vjs.zencdn.net/c/video-js.css" rel="stylesheet" type="text/css">
          <script src="http://vjs.zencdn.net/c/video.js"></script>
        </head>
        <body>
          <video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" width="640" height="264" poster="http://video-js.zencoder.com/oceans-clip.png" data-setup="{}">
            <source src="http://video-js.zencoder.com/oceans-clip.mp4" type='video/mp4' />
            <source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm' />
            <source src="http://video-js.zencoder.com/oceans-clip.ogv" type='video/ogg' />
          </video>
        </body>
    </html> 

This code show the videoplayer .but video is not playing while clicking play button.what's wrong?

please guide me. thanks in advance.


回答1:


Android has issues with playing video and can often only be triggered via JavaScript by adding a click event handler to the video element and playing the video once that is activated.

For example:

function play() {
   var video = document.getElementById('video');
   video.addEventListener('click',function(){
      video.play();
   },false);
}

You will probably need to adapt this code to work with yours though.




回答2:


Everything immediately worked for me. I'm using an iOS emulator.

Make sure you set the permission to go to that URL.

Cordova.plist --> externalhosts

You can use a wildcard to cover several URL's into one.




回答3:


Try to add this:

data-setup='{"controls":true}'



回答4:


Add the following to your main Activity

@Override
public void init() {
    super.init();

    this.appView.getSettings().setPluginsEnabled(true);
}



回答5:


We cant play video using in android. it works fine in iphone though. try using plugin for the purpose. check this out VideoPlayer Plugin



来源:https://stackoverflow.com/questions/9702691/how-to-play-video-using-html5-videoplayer-in-android-phonegap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!