我不知道为什么这个功能不起作用。
我现在使用一个非常简单的例子,在我的网站上,基本上停止视频一旦我点击链接。见下面的代码:
<div id="player"></div>
<a href="#" id="pause">Pause</a>这就是我在页面底部使用的脚本:
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '315',
width: '560',
videoId: 'bpOR_HuHRNs',
});
document.getElementById('pause').onclick = function() {
player.stopVideo();
};
}一旦我点击暂停链接。我知道错误:
Uncaught : player.stopVideo不是函数
我尝试实现google docs:Started的全部代码。
同样的problem..What在这里是错的??
发布于 2016-09-22 21:45:38
在您提供的链接上,tag.src与您的不同。看起来应该是
tag.src = "https://www.youtube.com/iframe_api";而你的
tag.src = "http://www.youtube.com/player_api";也许这就是问题所在?
发布于 2016-09-23 12:46:43
好吧,发现问题了..。如果有人会遇到同样的错误,请检查是否使用其他脚本,就像我使用reembed.com网站脚本作为自定义播放器制作YouTube视频一样。把整个YouTube的API搞砸了
发布于 2022-04-10 19:35:20
我也有这样的问题。
Uncaught TypeError: player.stopVideo is not a function我使用了tag.src = "https://www.youtube.com/iframe_api",并尝试实现google:Started的全部代码,但也遇到了同样的问题。
我已经为Drupal 9使用了页面,并发现为了youtube API的正确工作,它应该在主Drupal.behaviors.MyBehavior的末尾被称为函数onYouTubeIframeAPIReady()。它看起来像是:
Drupal.behaviors.playYouTubeVideos = {
attach(context) {
.........
....main_code_here....
......
onYouTubeIframeAPIReady();
}
};
})(jQuery, Drupal);https://stackoverflow.com/questions/39649268
复制相似问题