我正在使用 YouTube 视频播放器 API 在 iframe 中嵌入 YouTube 视频。我想隐藏右上角的播放按钮、视频标题和图标。这最初适用于我在下面编写的脚本。但是,一旦视频结束,视频将如下所示:
所有图标或标题都不可点击。为什么这些在视频结束后出现?如何编辑我的脚本以在视频结束时隐藏视频标题、播放按钮和右上角的图标?
到目前为止,这是我的脚本:
// download api code
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// this function creates an <iframe> and youtube player after the api code downloads
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '400',
width: '800',
playerVars: {
'autoplay': 1,
'controls': 0,
'autohide': 1,
'wmode': 'opaque',
'rel': 0,
'loop': 1
},
videoId: 'vlRxmgXPcW0',
events: {
'onReady': onPlayerReady
}
});
}
// the api will call this function when the video player is ready
function onPlayerReady(event) {
event.target.mute();
}
最佳答案
As of September 25, 2018 the
showinfo
parameter has been depreciated. https://developers.google.com/youtube/player_parameters#august-23,-2018
在构造函数参数中添加'showinfo' : 0,
所以:
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '400',
width: '800',
playerVars: {
'autoplay': 1,
'controls': 0,
'autohide': 1,
'showinfo' : 0, // <- This part here
'wmode': 'opaque',
'rel': 0,
'loop': 1
},
videoId: 'vlRxmgXPcW0',
events: {
'onReady': onPlayerReady
}
});
至于播放按钮,我认为您不能隐藏它——作为 youtube 的 api 品牌服务条款的一部分。
关于javascript - YouTube Player API 在 iframe 中隐藏播放按钮、图标和视频标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40095612/