2012-10-24 51 views
1

在我的網頁中,我有視頻,它有不同的3個來源。我需要在加載頁面時更改視頻src。爲此,我正在使用此功能,但我無法在iPad中更新,但Firefox正常工作。如何更新ipad中的視頻src

的jQuery:

$('#task2ResultVideo source').each(function (n,s) { 
     $('#task2ResultVideo').get(0).pause(); 
     $(this).attr('src',$(this).attr('src').replace('Task_2.4a_Host_treated', task2RslVideo)); 
     $(this).parents('video').get(0).load(); 
    }) 

HTML:

<video id="task2ResultVideo" autobuffer poster="img/task2-results-host-poster.jpg"> 
         <source src="Video/webm/Task_2.4a_Host_treated.webm" type="video/webm" /> 
         <source src="Video/ogv/Task_2.4a_Host_treated.theora.ogv" type="video/ogg" /> 
         <source src="Video/MP4/Task_2.4a_Host_treated.mp4" type="video/mp4" /> 
        </video> 

我感到困惑的高度,任何一個幫助我嗎?

我想這一點,在src更新,但視頻沒有加載,舊的視頻播放.. 的Jquery:

$('#task2ResultVideo source').each(function (n,s) { 
     $('#task2ResultVideo')[0].pause(); 
     $(this).attr('src',$(this).attr('src').replace('Task_2.4a_Host_treated', task2RslVideo)); 
     setTimeout(function(){ 
     $('#task2ResultVideo').load(); 
     },1000) 
     alert($(this).attr('src').replace('Task_2.4a_Host_treated', task2RslVideo)); 
    }) 
+0

什麼是task2RslVideo,它在哪裏聲明? –

+0

這是視頻的編號 – 3gwebtrain

回答

2

立足關「更換媒體順序」在蘋果開發者網站: http://developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/ControllingMediaWithJavaScript/ControllingMediaWithJavaScript.html#//apple_ref/doc/uid/TP40009523-CH3-SW1

在該文檔中,似乎Safari正在視頻標籤本身尋找src,而不是在其下面的<source/>標籤中。

一下,作爲一個簡單的測試,嘗試這個,看看它的工作原理是什麼:

// obviously, wrap this in a function... this is simply for testing, 
// as you'll want to refine this for use by other browsers as well, 
// if this works 
var $vid = $("#task2ResultVideo"); 
var src = "Video/MP4/" + task2RslVideo + ".mp4"; 
$vid.attr("src", src); 
$vid.get(0).load(); 
$vid.get(0).play(); 

好奇,想看看是什麼結果,你得到的,因爲這似乎是一個相當普遍的問題(我看到了很多的以及我在Google搜索中與此相關的問題)。

更新...當然它會失敗,因爲沒有設置,呃...我的壞。實際上,你的替換也是脆弱的,因爲它會第一次工作(因爲它知道'Task_2.4a_Host_treated'存在),但在此之後,它將不再有匹配。在這種情況下,你應該從你知道的組件構建你的src字符串,而不是使用replace。

+0

我收到此錯誤。 TypeError:'undefined'不是一個對象(評估'oldSrc.replace') – 3gwebtrain

+0

alerting alert(oldSrc);顯示未定義。這就是我在源代碼中找到的原因 – 3gwebtrain

+0

你爲我節省了很多時間。謝謝 – 3gwebtrain