im正在自定义我的youtube播放器,但我收到了一个错误,我已经检查了问题是否没有包装在就绪函数中,但仍然收到了错误"未捕获引用错误:未定义YT"
Js:
//youtube script
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
onYouTubeIframeAPIReady = function () {
player = new YT.Player('player', {
height: '193',
width: '284',
videoId: 'jGa2J3RBPtQ', // youtube video id
playerVars: {
'autoplay': 0,
'rel': 0,
'showinfo': 0
},
events: {
'onStateChange': onPlayerStateChange
}
});
}
onPlayerStateChange = function (event) {
if (event.data == YT.PlayerState.ENDED) {
$('.start-video').fadeIn('normal');
}
}
$(document).on('click', '.start-video', function () {
$(this).fadeOut('normal');
player.playVideo();
});
html:
<div id="player"></div>
<button class="start-video">Play</button>
您尝试过切换到HTTPS协议吗?
在这里为我工作
tag.src = "https://www.youtube.com/iframe_api";