gpt4 book ai didi

javascript - 强制 Youtube 嵌入以高清播放(2016 版)

转载 作者:数据小太阳 更新时间:2023-10-29 05:35:25 25 4
gpt4 key购买 nike

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

(不再)有效的方法:

  1. &hd=1 参数添加到 iframe src
  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
}
<div id="player"></div>  

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

有什么方法可以为简单的 iframe 嵌入运行 player.setPlaybackQuality('hd1080'); 函数?

最佳答案

你也可以设置你的playerVars

            vq: 'hd1080', 

144p: &vq=小

240p: &vq=小

360p:&vq=中等

480p:&vq=大

720p: &vq=hd720

1080p: &vq=hd1080

关于javascript - 强制 Youtube 嵌入以高清播放(2016 版),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35900906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com