2011-08-11 76 views

回答

0

您可以通過加載和播放這兩個視頻,同時將純音頻視頻保留在隱藏的DIV中,並使用JS API來靜音純視頻視頻來僞造它。

所以我會嘗試這樣的事:

<script type="text/javascript" src="swfobject.js"></script>  
<div id="videodiv"> 
The muted video will go here 
</div> 
<div id="audiodiv"> 
the hidden video will go here 
</div> 

<script type="text/javascript"> 
var audioplayer; 
var videoplayer; 

var params = { allowScriptAccess: "always" }; 
var video_atts = { id: "vidonly" }; 
var audio_atts = { id: "audonly" }; 

// embed the video-only player 
swfobject.embedSWF("http://www.youtube.com/e/VIDEO_ID?enablejsapi=1&playerapiid=ytplayer", 
        "videodiv", "425", "356", "8", null, null, params, atts); 

// embed the audio-only player 
swfobject.embedSWF("http://www.youtube.com/e/VIDEO_ID?enablejsapi=1&playerapiid=ytplayer", 
        "audiodiv", "425", "356", "8", null, null, params, atts); 


function onYouTubePlayerReady(playerId) { 
    audioplayer = document.getElementById("myytplayer"); 
    videoplayer = document.getElementById("myytplayer"); 

    videoplayer.mute(); 

    audioplayer.play(); 
    videoplayer.play(); 
} 

訣竅則是體現時尚與audiodiv CSS所以它不會顯示在網頁上。你可能需要玩弄它以找到最佳組合,但我猜測將其寬度和高度設置爲0或1應該足夠了。

另外,您可能需要設置onYouTubePlayerReady函數,以確保在開始播放之前兩個視頻都已完全加載。