简体   繁体   中英

html5 video tag not working in android phonegap

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='{"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.

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.

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.

除了 ghostCoder 下面所说的(添加点击处理程序来播放您需要为 Android 执行的视频)还尝试删除type='video/mp4'因为这有时会使 Android 感到困惑。

Add as a child in your activity manifest file.作为子项。 It plays html5 video inside webviews without any workaround.

eg

<activity
    android:name="com.example.MainActivity"
    android:hardwareAccelerated="true"
    android:configChanges="keyboardHidden|orientation|screenSize" >
    ...
</activity>

当您使用 Video 标签在 phonegap 应用程序中播放视频时,它在 iphone 上运行良好,但在 android 上运行良好。

try something like this

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

Are you sure you video stream is 'H.264' and audio stream id 'AAC' for MP4. Because I guess Android support MP4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM