1

I'm trying to embed a Youtube video to my site that plays automatically once the page is loaded.

I'm currently using:

<iframe width="560" height="315" src="https://www.youtube.com/embed/V4kXFYRhwL0" 
        frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

However the video doesn't play until clicked. What is wrong with this code?

Link to site: http://oxfordcliqr.com/

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Marcus
  • 114
  • 1
  • 1
  • 16

3 Answers3

9

Add this into the URL string: ?autoplay=1&mute=1

This will set the property autoplay to 1 and mute to 1, so the video starts playing once the page is loaded.

Due to the policy changes, autoplay videos only works if the video is muted.

Example:

<iframe width="560" height="315" src="https://www.youtube.com/embed/V4kXFYRhwL0?autoplay=1&mute=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
MrJami
  • 685
  • 4
  • 16
  • I've updated the code, but the video is still paused until the play button is clicked – Marcus Sep 11 '20 at 08:47
  • @Marcus the autoplay function like I mentioned before is not working since April 2018, google made some changes. – MrJami Sep 11 '20 at 09:36
1

pass autoplay=1 to auto play in youtube URL and mute=1 to mute it, both works when page get load completely

eg: <iframe width="560" height="315" src="https://www.youtube.com/embed/V4kXFYRhwL0?autoplay=1" ></iframe>

pl2ern4
  • 340
  • 2
  • 10
0

Use below iframe URL to the autoplay youtube video

<iframe width="420" height="315" src="https://www.youtube.com/embed/Zm4zpyn0ixw?autoplay=1&mute=1"></iframe>