无法在HTML5中播放视频

时间:2016-09-27 10:09:19

标签: jquery html5

在我的应用程序中,我有一个视频标签,我将动态附加src

这是我的代码

<video autobuffer controls autoplay>
  <source id="howtovideoimg" src="" type="video/mp4">
</video>


$( document ).ready(function() {
 $('#howtovideoimg').attr('src', 'http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4');
});

这是我的小提琴

http://jsfiddle.net/cod7ceho/125/

请让我知道如何播放视频

3 个答案:

答案 0 :(得分:1)

&#13;
&#13;
$( document ).ready(function() { 
  var player = document.getElementById('videoPlayer');
      var filepath = document.getElementById('videoPlayer');
      filepath.src = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4";

});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<video autobuffer controls autoplay id="videoPlayer">
  <source id="howtovideoimg" src="" type="video/mp4">
</video>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

你必须创建一个新的<source>元素,然后将它附加到视频标签,在javascript中动态添加元素很简单,我把js代码放在一个例子中,我认为这对你有帮助...

function addSourceElement() {
  var source = document.createElement('source');
  var video = document.createElement('video');
  source.src = 'http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4';
  source.type = 'video/mp4';

  video.appendChild(source);
  document.body.appendChild(video);
  video.play();
}

答案 2 :(得分:0)

只需使用这种JS:

-verbose

关于这个html:

$('#howtovideoimg source').attr('src', "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4");

我用来在页面加载源(白色视频)中有一个值,以避免浏览器上的一些奇怪的行为,如果它是空的,则不考虑源属性

相关问题