0

In my application i have a video tag for which i am appending src dynamically

this is my code

<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');
});

This is my fiddle

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

Please let me know how to play the video

Pawan
  • 28,159
  • 84
  • 232
  • 394

3 Answers3

1

$( 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";

});
<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>
Ganesh Putta
  • 2,792
  • 13
  • 23
0

You must create a new <source> element and then append it to video tag, it is simple to add the element dynamically in javascript, I put a example of js code, I think that can be of help for you...

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();
}
Mr Lister
  • 42,557
  • 14
  • 95
  • 136
M.Yakhyan
  • 7
  • 2
0

Simply use this kind of JS:

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

on this html:

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

I use to have a value in the source on page load (a white video) to avoid some weird behaviour on browser that do not consider the source attribute if it is empty

Lelio Faieta
  • 5,913
  • 6
  • 34
  • 57