Skip to content Skip to sidebar Skip to footer

YouTube Autoplay Workaround?

I understand the new changes to autoplay and how the video needs to be muted. But I have two questions to try and work around this feature. Since a site I'm working on uses specifi

Solution 1:

Okay so I found a few ways around this. The way allow="autoplay" works is that you need to have some sort of website interaction before it being able to run, then on every refresh after that it will autoplay. So what can you do?

  1. Make a play / unmute button. Of course this is the most time consuming way to go around things, as you would need to connect it to youtube's api.

  2. Make an alert. Alerts pose as a site interaction, so once the user clicks "okay" the script will run normally. Of course if you don't want it to alert the user every time there's a refresh, so a simple localhost script should work.

    if (localStorage.getItem("hasCodeRunBefore") === null) {
        var chrome   = navigator.userAgent.indexOf('Chrome') > -1;
   	if (chrome) alert('Click ok to load');
	window.onload = function () {
        localStorage.setItem("hasCodeRunBefore", true);
    }
}
  1. Tell your users to use "ctrl+r" if they are running chrome. As reloading the page will have it run just fine.

--

Of course this is only if you want autoplay with sound. If you don't care and just want a muted video, adding "?mute=1&amp" will work just fine.


Post a Comment for "YouTube Autoplay Workaround?"