我正在检查播放器的playerVars中的enablejsapi = 1选项为here 但这不起作用。 我创建了一个plnkr here
这是我的HTML:
<!DOCTYPE html>
// 1. The <iframe> (and video player) will replace this <div> tag.
<div id="player"></div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
},
playerVars: {
enablejsapi: 0,
controls: 0
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
</script>
我只是将playerVars放在构造函数中,其余代码与iframe api reference
中给出的相同默认情况下,文档链接表示值为0,但生成的iframe如下所示:
<iframe id="player" frameborder="0" allowfullscreen="1" title="YouTube video player" width="640" height="390" src="https://www.youtube.com/embed/M7lc1UVf-VE?enablejsapi=1&controls=0&widget_referrer=https%3A%2F%2Frun.plnkr.co%2Fpreview.html&origin=https%3A%2F%2Frun.plnkr.co&widgetid=1"></iframe>
因为我们可以看到enablejsapi设置为1,尽管我在playerVars中将其设置为0。 controls参数初始化为0。
那么为什么会这样呢?
我建议youtube iframe api团队调查它(报告SO,因为他们说他们按照https://developers.google.com/youtube/players/support跟踪问题)