1
votes

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/

3

3 Answers

4
votes

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>
1
votes

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>

0
votes

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>