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);
}
}
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.
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.
You can set 'playerVars' in the second parameter of "YT.Player": https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player
This works fine for me:
player = new YT.Player('divId', {
videoId : videoSrc,
playerVars: {
'autoplay': 0,
'controls': 1,
'rel' : 0,
'fs' : 0,
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With