【发布时间】:2011-12-24 19:35:48
【问题描述】:
我正在尝试嵌入高清 YouTube 视频,但无论我尝试什么,它似乎都只能加载 480p 版本。
根据 YouTube 的说法,嵌入高清视频就像在 URL 中添加 hd=1 一样简单:
<iframe src="//www.youtube.com/embed/{videoId}?hd=1" width="960" height="720" frameborder="0" allowfullscreen></iframe>
但是,这似乎不起作用,至少在我实现 iframe 时:
<iframe id="video-player" width="960" height="720" src="//www.youtube.com/embed/{videoId}?enablejsapi=1&autoplay=1&rel=0&modestbranding=1&showinfo=0&showsearch=0" frameborder="0" allowfullscreen></iframe>
Javascript API 也是如此:
HTML:
<div id="video-player"></div>
JS:
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('video-player', {
height: '720',
width: '960',
videoId: '{videoId}',
playerVars: {
'controls': 1,
'autoplay': 1,
'hd': 1
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
player.playVideo();
}
【问题讨论】:
标签: iframe youtube embed youtube-api