2013-12-08 122 views
2

我使用JW播放器來播放YouTube視頻,但我需要的視頻開始在HD(720p)的打我使用下面的代碼:設置JW播放YouTube視頻的播放質量

<div id="player"> 
<script> 
jwplayer("player").setup({ 
     file: "http://www.youtube.com/watch?v=o8UCI7r1Aqw", 
     height: "720", 
     width: "1280" 
    }); 
</script> 
</div> 
<script> 
jwplayer('player').onPlay(function() { 
jwplayer().setPlaybackQuality('hd720'); 
}); 
</script> 

但我出現以下錯誤

出現錯誤回調的事件處理程序

Here是測試球員,我成立。

回答

1

setPlaybackQuality不是一個有效的API調用 - http://www.longtailvideo.com/support/jw-player/28851/javascript-api-reference

這裏是有效的質量API調用的列表:

Quality 

These API calls are used to listen to or update the video quality if multiple quality levels of a video are provided. 

getQualityLevels() 
    Returns an array with quality levels from the player. Each level is an object that contains a label property. 
getCurrentQuality() 
    Returns the index of the currently active quality level. 

setCurrentQuality(index) 
    Change the quality level to the provided index. The index must be within the list provided by getQualityLevels. 

onQualityLevels(callback) 
    Fired when the list of available quality levels is updated. Happens e.g. shortly after a playlist item starts playing. Event attributes: 

     levels (Array): the full array with new quality levels. 

onQualityChange (callback) 
    Fired when the active quality level is changed. Happens in respons to e.g. a user clicking the controlbar quality menu or a script calling setCurrentQuality. Event attributes: 

     currentQuality (Number): index of the new quality level in the getQualityLevels() array. 
+0

感謝對你的迴應@ethan但是從我瞭解這些API調用只有當我列出了可用的質量級別,而不是如果我使用YouTube,至少我試過setCurrentQuality('720'),但它沒有工作 – user3079856

+0

它應該與YouTube一起工作,以及本地質量列表。我能看到它不工作的地方嗎? – emaxsaun

+0

Sure @ethan [here](http://videogg.com/test.html) – user3079856

2

我的解決方案是原生的YouTube API。 (從https://developers.google.com/youtube/iframe_api_reference#setPlaybackQuality



Demo
(但它有一個缺陷:您可以切換到上質量,但後來它不進入低質量...)

<div id="MyPlayerDivIDD1"></div> <div id="MyQualities"></div> 

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> 
<script type="text/javascript" src="http://www.youtube.com/player_api"></script> 
<script type="text/javascript"> 
function onYouTubePlayerAPIReady() { 
    ytp1 = new YT.Player('MyPlayerDivIDD1', { height: '200', width: '290', videoId: 'Rk6_hdRtJOE',   playerVars: { 'autoplay': 1, 'controls': 1 , 'autohide':0,},     events: {'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange }       }); 
    var startedd=false; var MyQuality; 
} 
function onPlayerReady(event) {} 
function onPlayerStateChange(event) { if (event.data == YT.PlayerState.PLAYING && !startedd) { SetQuallll(event);startedd=true; } } 
function SetQuallll(event) { MyQuality = MyQuality || 'tiny'; event.target.setPlaybackQuality(MyQuality); } 
</script> 



<br/> <a href="javascript:ShowMenu();">SHOW QUALITY Switcher </a> 
<script> 
function ShowMenu(){ 
    AllQualities = ytp1.getAvailableQualityLevels(); AllQualities.push("hd720"); AllQualities.push("hd1080"); 
    for (var i=1; i<AllQualities.length; i++) { document.getElementById("MyQualities").innerHTML += ' <a href="javascript: startedd=false; MyQuality=\''+AllQualities[i]+'\'; alert(\'Current Qualityy:\'+ytp1.getPlaybackQuality() + \' --------- Switching To:'+AllQualities[i]+'\'); ytp1.pauseVideo(); ytp1.setPlaybackQuality(\''+AllQualities[i]+'\'); ytp1.playVideo(); void(0); ">'+i + ')' + AllQualities[i]+'</a> '; } 
}</script>