【问题标题】:Force Youtube embed to play in HD (2016 edition)强制嵌入 Youtube 以高清播放(2016 版)
【发布时间】:2016-06-24 09:03:48
【问题描述】:

好的,这已经被问过很多次了——但 Youtube 似乎每隔一天就会改变一次。我找不到强制嵌入 Youtube 从头开始​​播放高清源的方法。切换到高清总是在 5-10 秒后发生。

不再起作用的方法:

  1. 在 iframe src 中添加 &hd=1 参数
  2. 将&vd=hd720 或&vd=hd1080 参数添加到iframe src。此处描述:Force youtube embed to start in 720p
  3. 在 html 嵌入代码中将 iframe 尺寸更改为 width="1280" heigh="720",然后使用 CSS 将 iframe 缩小/放大到父 div。此处描述:http://thenewcode.com/717/Force-Embedded-YouTube-Videos-To-Play-In-HD 和此处:How to force youtube to play HD videos

唯一可能的方法是使用 Youtube JavaScript API,如下所述: http://biostall.com/the-100-guaranteed-method-to-get-youtube-iframe-embeds-playing-in-hd-by-default/

// 1. This code loads the IFrame Player API code asynchronously.  
 var tag = document.createElement('script');  
  
tag.src = "https://www.youtube.com/iframe_api";  
var firstScriptTag = document.getElementsByTagName('script')[0];  
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);  
  
// 2. This function creates an <iframe> (and YouTube player) after the API code downloads.  
var player;  
function onYouTubeIframeAPIReady() {  
    player = new YT.Player('player', {  
        height: '1280',  
        width: '720',  
        videoId: 'E37YNMYlKvo',  
        events: {  
            'onReady': onPlayerReady  
        }  
    });  
}  
  
// 3. The API will call this function when the video player is ready.  
function onPlayerReady(event) {  
    player.setPlaybackQuality('hd1080'); // Here we set the quality (yay!)  
    event.target.playVideo(); // Optional. Means video autoplays  
}  
&lt;div id="player"&gt;&lt;/div&gt;  

但是:我想使用简单的 iframe 嵌入,因为视频将通过 wordpress oembed 功能嵌入。

有没有办法为简单的 iframe 嵌入运行 player.setPlaybackQuality('hd1080'); 函数?

【问题讨论】:

    标签: javascript iframe youtube embed


    【解决方案1】:

    你也可以设置你的 playerVars

                vq: 'hd1080', 
    

    144p: &vq=小

    240p: &vq=小

    360p:&vq=中等

    480p: &vq=大

    720p: &vq=hd720

    1080p: &vq=hd1080

    【讨论】:

      【解决方案2】:

      据我了解,似乎有一个 'VQ' 参数,您可以将其附加到嵌入 iframe 的末尾并将 hd720 或 hd1080 设置为值。经过一些研究,YouTube 似乎曾经提供过 'VQ' 参数,然后将其取消,并且在撰写本文时又回来了!简而言之,您的嵌入应该如下所示:

      &lt;iframe src="https://www.youtube.com/embed/VIDEO_ID_HERE?vq=hd1080" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;

      这是我在研究过程中发现的一篇与此相关的文章:Found Here

      我已经在一个页面上对此进行了简短的测试,它似乎可以工作(目前)。希望这会有所帮助!

      【讨论】:

        猜你喜欢
        • 2012-09-25
        • 2014-11-19
        • 2013-10-29
        • 2018-08-19
        • 2016-03-19
        • 2015-02-19
        • 2015-03-20
        • 2011-12-24
        • 2012-05-02
        相关资源
        最近更新 更多