RyanP
RyanP

Reputation: 43

Best way to add youtube video to HTML?

I know this question may have been asked before, but no good answers were found while I was searching.

I have a website where I want to add a YouTube video. The goal is to have an autoplaying video with sound on. A lot of users recommended using the html tag iframe to embed it, which seemed to work perfectly with autoplaying except for the sound.

Does anyone know a better solution to this? Would it be better to just upload the video to the server and use the video tag?

    <iframe
  width="100%"
  height="100%"
  src="https://youtube.com/embed/h4gr8eH7D?autoplay=1&amp;controls=0&amp;showinfo=0&amp;autohide=1&amp;mute=1&amp;playlist=h4gr8eH7D&amp;loop=1"
  allow="autoplay"
></iframe>

Supposedly they updated using autoplay=1 to where it had to have mute=1 which makes autoplay work, but with no sound. I saw somewhere someone had used mute=2 to have the audio working, but that didn't work for me either.

Upvotes: 0

Views: 178

Answers (1)

Seif El-Din Sweilam
Seif El-Din Sweilam

Reputation: 274

The new versions of Chrome prevent any audio from running on a webpage until the user interacts with the page. You CANNOT auto-play a video in a chrome browser unless it's muted and this also applies to videos which you upload to your server. If you'll make the user interact with your page before playing audio, you'll be able to play it.

See also How to make audio autoplay on chrome.

Upvotes: 1

Related Questions