14

I have an html5 video streaming and I need to change it source* after some click action. So what i'm doing works, but only in html, i can see source change but it no changing on my display, can you help me? What is wrong? *The source is appending frome xml file.

HTML

<video autoplay loop width="960" height="540" id="video">
    <source src="video/movie_01.mp4" id="tv_main_channel">
</video>

JS

btn.on('click', function(){
    var tv_main_channel = $('#tv_main_channel'),
        d_program_source_mp4 = $(program_self).find("program_source_mp4").text();

    tv_main_channel.attr('src', d_program_source_mp4);
}

also i try it with append but it still not work

var video_block = $('#video');

video_block.empty();
video_block.append(
    '<source src="'+ d_program_source_mp4 +'">'
);

Thx for help.

Lukas
  • 7,384
  • 20
  • 72
  • 127

3 Answers3

28

See this fiddle: http://jsfiddle.net/qGbzb/2/

To dynamically load videos you need to run

var video_block = $('#video');
video_block.load();

Then you should also see a change in the display too, and not only in the html.

richie
  • 2,448
  • 3
  • 19
  • 21
14

It's simple, just do this:

btn.on("click", function(){
  var src = "new_video_src.mp4";
  $("#video").find("#tv_main_channel").attr("src", src)
})
Eric Martins
  • 460
  • 4
  • 17
0

You can use like this in click event

  var src = "new_video_src.mp4";
  $("#tv_main_channel").src=src;

This is the actual method for video tag elements

Manu M
  • 1,074
  • 5
  • 17