2012-04-23 100 views
0

不改變,我試圖改變一個視頻源中的HTML5,但在Safari它不改變它,我試圖做到這一點的方式:HTML5視頻源在Safari

這裏是我的JQUERY:

$(".video").click(function(){ 
    var str = $(this).attr("id"); 
    var nww = str.substring(0, str.length - 4); 
    $(".id").append(nww); 
    $("#vid source:eq(0)").attr("src", nww+".mp4"); 
    $("#vid source:eq(1)").attr("src", nww+".ovg"); 
    $("#vid source:eq(2)").attr("src", nww+".webm"); 
    $("#vid")[0].load(); 
    }); 

這裏是我的HTML(按鈕點擊):

<div class="vid"> 
    <a id="http://cancunvideo.com/videos/localidades/cancun/spa/renova_spa_riu_caribe/assets/videos/Hotel_Riu_Caribe.mp4" class="video"> 
     <img src="http://cancunvideo.com/videos/localidades/cancun/spa/renova_spa_riu_caribe/assets/videos/Hotel_Riu_Caribe.jpg" width="230" height="120" border="0" /> 
    </a> 
</div> 

,這裏是我的視頻HTML:

<div id="mainVid"> 
    <video id="vid" width="640" height="360" poster="http://cancunvideo.com/videos/toyota_cancun/hossana/sources/template_toyota.png" autoplay="autoplay" controls style="display: block;"> 

     <!-- This is the path for the video. It's in webm format --> 
    <source src="<?php echo $webm ?>" type='video/webm; codecs="vp8, vorbis"' /> 
     <!-- This is the path for the video. It's in OGV format --> 
    <source src="<?php echo $ovg ?>" type='video/ogg; codecs="theora, vorbis"' /> 
     <!-- This is the path for the video. It's in mp4 format --> 
    <source src="<?php echo $mp4 ?>" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /> 

    When a browser can't handle the poster fallback, it will show this P tag instead. Which happens to be the same static image. 
    <p width="640" height="360" align=style="display: block; line-height: 1px;"><img src="http://cancunvideo.com/videos/toyota_cancun/hossana/sources/template_toyota.png" id="poster" alt="Poster" width="640" height="360" border="0" style="display: block;"></p> 
    </video> 
    <!-- first try HTML5 playback: if serving as XML, expand `controls` to `controls="controls"` and autoplay likewise --> 
<!-- warning: playback does not work on iOS3 if you include the poster attribute! fixed in iOS4.0 --> 

    </div> 

Safari中會發生什麼,它改變了所有的源,但只改變了第一個在jquery(MP4)中調用的源。並在Firefox中將它們全部更改爲最後一個(.jpg)..任何幫助在這裏將不勝感激。我跑進了一堵牆!謝謝!

回答

0

相反的$('.video').click(function(){...}),嘗試做

$('.video').each(function(){ 
    $(this).click(function(){ 
     ... 
    }) 
}) 
+0

都能跟得上沒有工作:( – liveandream 2012-04-23 15:22:45