我的解決方案是原生的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>
感謝對你的迴應@ethan但是從我瞭解這些API調用只有當我列出了可用的質量級別,而不是如果我使用YouTube,至少我試過setCurrentQuality('720'),但它沒有工作 – user3079856
它應該與YouTube一起工作,以及本地質量列表。我能看到它不工作的地方嗎? – emaxsaun
Sure @ethan [here](http://videogg.com/test.html) – user3079856