问题
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