javascript html5 视频标签在 android phonegap 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9716526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
html5 video tag not working in android phonegap
提问by Mercy
I have created application in android phonegap.I want to play video using html5 video player. My code is:
我在 android phonegap 中创建了应用程序。我想使用 html5 视频播放器播放视频。我的代码是:
<!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='{"controls":true}'>
<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.
此代码显示视频播放器。但单击播放按钮时未播放视频。有什么问题?请指导我。提前致谢。
回答by Leonardo Montenegro
You said it didn't worked on emulator, right? Don't you think video isn't being reproduced mainly because on Android SDK emulator you probably don't have any hardware acceleration for it? Some things don't work properly (sometimes don't work at all) if you don't have HW acceleration and a device powerful enough for that.
你说它在模拟器上不起作用,对吧?你不认为视频没有被复制主要是因为在 Android SDK 模拟器上你可能没有任何硬件加速吗?如果您没有硬件加速和足够强大的设备,有些事情将无法正常工作(有时根本无法工作)。
If that's the case, a workaround is using videos in 3GP format. That should work Android SDK emulator, and on older Android-powered cellphones with weak hardware. I used that on a project of mine.
如果是这种情况,解决方法是使用 3GP 格式的视频。这应该适用于 Android SDK 模拟器,以及硬件较弱的旧 Android 手机。我在我的一个项目中使用了它。
回答by Ian Devlin
In addition to what ghostCoder says below (adding a click handler to play the video which you need to do for Android) also try removing type='video/mp4'
as this sometimes confuses Android.
除了下面ghostCoder所说的(添加一个点击处理程序来播放您需要为Android做的视频)之外,还尝试删除,type='video/mp4'
因为这有时会混淆Android。
回答by Ramanan
Add android:hardwareAccelerated="true"as a child in your activity manifest file. It plays html5 video inside webviews without any workaround.
在您的活动清单文件中添加android:hardwareAccelerated="true"作为子项。它在没有任何解决方法的情况下在 webviews 中播放 html5 视频。
eg
例如
<activity
android:name="com.example.MainActivity"
android:hardwareAccelerated="true"
android:configChanges="keyboardHidden|orientation|screenSize" >
...
</activity>
回答by Neji
When you use Video tag for playing video in phonegap app,it works well on iphone but not on android.
当您使用 Video 标签在 phonegap 应用程序中播放视频时,它在 iphone 上运行良好,但在 android 上运行不正常。
回答by ghostCoder
try something like this
尝试这样的事情
var video = document.getElementById('video');
video.addEventListener('click',function(){
video.play();
},false);
回答by Tarun
Are you sure you video stream is 'H.264' and audio stream id 'AAC' for MP4. Because I guess Android support MP4
您确定您的视频流是“H.264”,而 MP4 的音频流 ID 是“AAC”吗?因为我猜安卓支持 MP4