YouTube autoplay not working in Chrome

chechu picture chechu · May 7, 2018 · Viewed 51.3k times · Source

For a while now I have been using this script, where the video is automatically playing full-screen. For now suddenly the video doesn't play automatically in Chrome. But in Firefox and Edge it still works.

So maybe Google changed settings? Does anyone know how to fix this, please? You see the live example here: www.brunomazereel.com

<script src="http://www.youtube.com/player_api"></script>
<script type="text/javascript">
var player;
function onYouTubePlayerAPIReady() {
    player = new YT.Player('player', {
    playerVars: {
        'autoplay': 1,
        'controls': 0,
        'autohide': 1,
        'wmode': 'opaque',
        'showinfo': 0,
        'loop': 1,
        'rel': 0,
        'playlist': 'rh5QiehIlVA,Bl63bdR-Ko0,'
        },
    videoId: 'u-cjliof1xk',
    events: {
        'onReady': onPlayerReady
    }
});
}
function onPlayerReady(event) {
event.target();
$('#text').fadeIn(400);
}
$(window).scroll(function() {
var hT = $('.m-video').height(),
   wS = $(this).scrollTop();
if (wS > hT) {
  player.pauseVideo();
}
else {
  player.playVideo();
}
});
</script>

Answer

Alexandre Beaudet picture Alexandre Beaudet · May 7, 2018

(One) of the possible solution taken from the comments discussion would be muting the video if sound isn't that important in your case (if it is, I'll leave the answer as it could help other people).

It's apparently the only way to have autoplay always enabled. From the article :

"Muted autoplay is always allowed."

Source : Google changelog


Simply add in your playerVars:

mute : 1

Source for the muted video