Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change source in html5 video with jQuery [duplicate]

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.

like image 324
Lukas Avatar asked Feb 10 '13 15:02

Lukas


2 Answers

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.

like image 153
richie Avatar answered Oct 06 '22 13:10

richie


It's simple, just do this:

btn.on("click", function(){
  var src = "new_video_src.mp4";
  $("#video").find("#tv_main_channel").attr("src", src)
})
like image 36
Eric Martins Avatar answered Oct 06 '22 15:10

Eric Martins