It seems that the documentation of the iFrame API is either outdated or completely wrong.(iFrame API的文档似乎已过时或完全错误。)
The function which should initialize the player onYouTubeIframeAPIReady() will never fire thus a click on the play/pause buttons won't work because the variable player is undefined .(应该在YouTubeIframeAPIReady()上初始化播放器的函数将永远不会触发,因此单击播放/暂停按钮将不起作用,因为变量播放器 未定义 。)
To workaround this, you have to wait until the script you're loading into the freshly created <script>
element has finished loading and inside the callback function you need to initialize the YT component by a call to it's own ready() function.(要解决此问题,您必须等到要加载到刚创建的<script>
元素中的<script>
完成加载,并且需要在回调函数内部通过调用其自己的ready()函数来初始化YT组件。)
This isn't mentioned anywhere.(这在任何地方都没有提及。)
Well, get rid of the complete onYouTubeIframeAPIReady function and replace it with this:(好吧,摆脱完整的onYouTubeIframeAPIReady函数并将其替换为:)
tag.onload = function() {
YT.ready(function() {
player = new YT.Player('player', {
height: '250',
width: '300',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
}
});
});
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…