1

We have a number of video references in our web app which lazy load YouTube videos as embedded iframes. We want to have the videos autoplay so a single user click will suffice to load the YouTube iframe into the page and start its playback. We've had this working as recently as a few months ago, but the autoplay is no longer occurring. I know there was an update to Google/YouTube policies in the spring of 2018 which limited autoplay; has there been a more recent change I don't know about? Otherwise, does anyone know why this might have stopped working?

I've tried the most recent iframe examples I could find online, with several variations (e.g., with and without mute=1). None of these seem to work.

Here's an example of our iframe markup:

<iframe allow="autoplay" frameborder="0" allowfullscreen="" src="https://www.youtube.com/embed/sapLz6NjvJk?autoplay=1&origin=https://OurWebsiteDomain" title="Bug Week " height="278" data-ytbridge="vidSurrogate2" style="width: 100%;"></iframe>
Clifford
  • 88,407
  • 13
  • 85
  • 165
RRitchie
  • 13
  • 1
  • 1
  • 5

1 Answers1

5

Major browser have disabled these features due to general abuse.
https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
https://blog.mozilla.org/firefox/block-autoplay/

YouTube checks upon loading whether it has permission to play how it wants to play the video. It will only autoplay if it has proper permission. The default in recent Chrome and Firefox builds is to only allow video - no sound. Adding &mute=1 the the youtube URL allows (muted) autoplay. This works if you don't necessarily need the sound, if you do then you will have to make the user click play themselves.

Applying this to the embed in your example:
<iframe allow="autoplay" frameborder="0" allowfullscreen="" src="https://www.youtube.com/embed/sapLz6NjvJk?autoplay=1&mute=1&origin=https://OurWebsiteDomain" title="Bug Week " height="278" data-ytbridge="vidSurrogate2" style="width: 100%;"></iframe>

Daniel_I_Am
  • 196
  • 1
  • 5
  • I've never gotten the mute=1 flag to work for this. Is something required in addition to the flag? – RRitchie Oct 01 '19 at 18:37
  • Added a minimum example to the answer. Nothing aside from the get parameter `mute=1` should be necessary to make them autoplay, although muted. – Daniel_I_Am Oct 01 '19 at 20:02
  • why when i change your video id from `"sapLz6NjvJk"` to my video id `"edcJ_JNeyhg"`, it become not working? – Michelle Lidz May 06 '21 at 10:41
  • This could be one of two things. One option is that this particular video has embeds disabled (it is an option in YouTube that can be disabled by the uploader). Another possibility could be that it doesn't work with 360-video, but that seems less likely. You could test this by uploading a 360-video yourself and testing if you can embed that. – Daniel_I_Am May 07 '21 at 15:04