Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Youtube Player API hide controls, hide info, hide related videos?

Tags:

youtube

api

I am trying to load a Youtube video in the home page (Chromeless) useing JavaScript API. So far I managed to make it auto play, hd720 and fadeOut the video once it is finished.

But I can't find a way to remove controls, hide info and not to load related video at the end.

I know in iframe embed I can use below parameters

controls=0&showinfo=0&autoplay=1&rel=0

But I can't find way to use these parameters in YouTube Player API shown below. Any suggestion?

<script src="http://www.youtube.com/player_api?enablejsapi=1&version=3"></script>

  function onYouTubePlayerAPIReady() {
            player = new YT.Player('video_chromeless', {
                height: '800',
                width: '450',
                videoId: '',
              events: {
                'onReady': onPlayerReady,
                'onStateChange': onPlayerStateChange
              }
            });
        }
function onPlayerReady(event){
            player.setPlaybackQuality('hd720');
            event.target.playVideo();
        }
 function onPlayerStateChange(event) {
            if(event.data === 0) {
                $('#video_chromeless').fadeOut(600);
            }
        }
like image 390
AK4668 Avatar asked Aug 10 '12 11:08

AK4668


People also ask

How do I hide YouTube player controls?

hyde — hide the YouTube video player controls. Press Ctrl+M to hide or show the YouTube video player controls. When you pause a YouTube video, the player controls don't disappear. That makes it really hard to take a clean screenshot of the video.

Does Rel 0 still work?

YouTube changed the rel=0 parameter as of September 2018 so that it no longer fully disables related videos. However, you can work around this using the YouTube Player API to show custom HTML instead of related videos.


2 Answers

You can set 'playerVars' in the second parameter of "YT.Player": https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player

like image 63
Johni Avatar answered Oct 05 '22 17:10

Johni


This works fine for me:

player = new YT.Player('divId', {
    videoId : videoSrc,
    playerVars: { 
        'autoplay': 0,
        'controls': 1, 
        'rel' : 0,
        'fs' : 0,
    }
});
like image 26
PsychoScripter Avatar answered Oct 05 '22 16:10

PsychoScripter