-1

I cannot proceed the code cause my code wont work please advise on this code

<div id="video-section-pop">
 <button id="close">X</button><br>
 <video controls autoplay>
    <iframe width="100%" height="250" src="https://www.youtube.com/embed/4J-VkbOwulM" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
 </video>   
</div>
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75

1 Answers1

0

Reason

More browser changes their Autoplay Policy, such as Google:

Chrome's Autoplay Policy had change in April of 2018

Muted autoplay is always allowed. Autoplay with sound is allowed if:

  • Muted autoplay is always allowed.
    • Autoplay with sound is allowed if:
    • User has interacted with the domain (click, tap, etc.).
    • On desktop, the user's Media Engagement Index threshold has been crossed, meaning the user has previously play video with sound.

Solution

You don't need to add youtube's Iframe to the video tag, you just need to add two query strings to youtube's URL

  • autoplay=1
  • mute=1

it's also working on another modern browser

<iframe ... src="https://www.youtube.com/embed/4J-VkbOwulM?autoplay=1&mute=1"></iframe>

you can check complete code on https://jsfiddle.net/tf3gpb1r/5/


More Reference

Chunbin Li
  • 2,196
  • 1
  • 17
  • 31