最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery and change html 5 video source on click - Stack Overflow

programmeradmin2浏览0评论

I know this has been asked before but for some reason that strategy doesn't seem to be working for me.

this is my code:

   $(document).ready(function() {
        $('#foo').click(function() {
        var videoFile = 'video/law_cash.mp4';
        $('#video_container video source').attr('src', videoFile);
        });
    });

the click function works and also when I check in firebug the video/law_cash.mp4 shows up in the right area. It just wont load when I click

EDIT: this is what im actually trying to do:

$(document).ready(function() {

    var knicks = 'video/knicks_therapist.m4v';
        law = 'video/law_cash.mp4';
        fit = 'video/fit_some.mp4';
        texas = 'video/texas_familia.mp4';
        partner = 'video/drug.m4v';
        keyspan = 'video/keyspan_nrg.mov';

    $('#law').click(function() {
        $('#video_container video source').attr('src', law);
        $('#video_container video source').load();
    });

    $('#knicks').click(function() {
        $('#video_container video source').attr('src', knicks);
        $('#video_container video source').load();
    });

    $('#fit').click(function() {
        $('#video_container video source').attr('src', fit);
        $('#video_container video source').load();
    });

    $('#texas').click(function() {
        $('#video_container video source').attr('src', texas);
        $('#video_container video source').load();
    });

    $('#partner').click(function() {
        $('#video_container video source').attr('src', partner);
        $('#video_container video source').load();
    });

    $('#keyspan').click(function() {
        $('#video_container video source').attr('src', keyspan);
        $('#video_container video source').load();
    });
});

html:

<a id="law" href="#">BLAH</a>

I know this has been asked before but for some reason that strategy doesn't seem to be working for me.

this is my code:

   $(document).ready(function() {
        $('#foo').click(function() {
        var videoFile = 'video/law_cash.mp4';
        $('#video_container video source').attr('src', videoFile);
        });
    });

the click function works and also when I check in firebug the video/law_cash.mp4 shows up in the right area. It just wont load when I click

EDIT: this is what im actually trying to do:

$(document).ready(function() {

    var knicks = 'video/knicks_therapist.m4v';
        law = 'video/law_cash.mp4';
        fit = 'video/fit_some.mp4';
        texas = 'video/texas_familia.mp4';
        partner = 'video/drug.m4v';
        keyspan = 'video/keyspan_nrg.mov';

    $('#law').click(function() {
        $('#video_container video source').attr('src', law);
        $('#video_container video source').load();
    });

    $('#knicks').click(function() {
        $('#video_container video source').attr('src', knicks);
        $('#video_container video source').load();
    });

    $('#fit').click(function() {
        $('#video_container video source').attr('src', fit);
        $('#video_container video source').load();
    });

    $('#texas').click(function() {
        $('#video_container video source').attr('src', texas);
        $('#video_container video source').load();
    });

    $('#partner').click(function() {
        $('#video_container video source').attr('src', partner);
        $('#video_container video source').load();
    });

    $('#keyspan').click(function() {
        $('#video_container video source').attr('src', keyspan);
        $('#video_container video source').load();
    });
});

html:

<a id="law" href="#">BLAH</a>
Share Improve this question edited Nov 30, 2010 at 3:23 Robert asked Nov 30, 2010 at 2:56 RobertRobert 81613 silver badges29 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

Firefox doesn't support MPEG audio/video formats... dunno why.

EDIT: If you have an onerror event registered then it would fire, and the video element's error object will tell you MEDIA_ERR_SRC_NOT_SUPPORTED

In the original example, I believe the code snippet to load the video should be

$('#video_container video').load();

(without 'source' tag after 'video' tag)

Just use javascript

video.src = 'new/url/video.ogv';
video.load();  // Load the new video
video.play();  // Play it
发布评论

评论列表(0)

  1. 暂无评论