编辑:这是JSFiddle:http://jsfiddle.net/sr4u1b0a
我正在尝试弄清楚如何使用YouTube API。我是新手,所以如果有一个简单的解决方案,我很抱歉。
我相信我添加了所有必要的代码以使其正常工作,它只是不会加载视频。
https://codepen.io/brianpensinger/pen/zdxzjj
目:
<script src="https://youtube.com/iframe_api" type="text/javascript"></script>
<script type="text/javascript">
var player2;
function onYouTubeIframeAPIReady() {
player2 = new YT.Player("video-placeholder2", {
width: 1920,
height: 1080,
videoId: "iM_KMYulI_s",
playerVars: {
modestbranding: 1,
rel: 0
},
events: {
onReady: initialize
}
});
}
function initialize() {
setPlaybackQuality(highres);
loadVideoById(iM_KMYulI_s, parseInt(0), highres);
setPlaybackRate(2);
}
</script>
<script type="text/javascript">
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player("video-placeholder", {
width: 1920,
height: 1080,
videoId: "iM_KMYulI_s",
playerVars: {
modestbranding: 1,
rel: 0
},
events: {
onReady: initialize
}
});
}
function initialize() {
setPlaybackQuality(highres);
loadVideoById(iM_KMYulI_s, parseInt(0), highres);
setPlaybackRate(2);
}
</script>
答案 0 :(得分:1)
更新,我改为通过这个脚本加载,它工作正常!
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);