最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - YouTube Player API hide play button, icons, & video title in iframe - Stack Overflow

programmeradmin0浏览0评论

I am using the YouTube video player API to embed a YouTube video in an iframe. I want to hide the play button, video title, and icons in the top right corner. This is working initially with the script I wrote below. However, once the video es to an end the video looks like this:

None of the icons or the title are clickable either. Why do these appear once the video ends? How can I edit my script to hide the video title, play button, and the icons in the top right corner when the video ends?

Here is my script so far:

// download api code
var tag = document.createElement('script');
tag.src = "";
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();
}

I am using the YouTube video player API to embed a YouTube video in an iframe. I want to hide the play button, video title, and icons in the top right corner. This is working initially with the script I wrote below. However, once the video es to an end the video looks like this:

None of the icons or the title are clickable either. Why do these appear once the video ends? How can I edit my script to hide the video title, play button, and the icons in the top right corner when the video ends?

Here is my script so far:

// download api code
var tag = document.createElement('script');
tag.src = "http://www.youtube./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();
}
Share Improve this question asked Oct 17, 2016 at 21:03 LizLiz 1,0485 gold badges23 silver badges51 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

As of September 25, 2018 the showinfo parameter has been depreciated. https://developers.google./youtube/player_parameters#august-23,-2018

Add 'showinfo' : 0, to the constructor parameters

So:

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
    }
});

As far as the play button, I don't believe you are allowed to hide that -- as its part of youtube's api branding terms of service.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论