0

I doing a website where I need to put a background video on a div. Everything work fine except the autoplay on Chrome.

I have both autoplay and muted on my tag and I've tried too with a javascript that play the video but neither of theses worked for me.

video id="myVideo" autoplay muted loop

and

document.getElementById('myVideo').play()

On safari it works fine, but when I try on Chrome, the video never autoplay. If I run the script on the Chrome console, it starts playing so I don't know what to do...

jepi
  • 1
  • 2
  • 1
    Welcome to Stack Overflow. Please always post the relevant code that you are working (HTML, CSS, JavaScript) in a "code snippet" so that we can reproduce your issue. Also, in this case, please describe what you mean by "background video". – Scott Marcus Feb 01 '19 at 18:29
  • Please check out some related threads to see if they can answer your question: https://stackoverflow.com/questions/52830264/html5-video-autoplay-not-working-in-chrome – Val Geyvandov Feb 01 '19 at 18:29
  • [Apparently, there's a change in chrome's policy and I found this workaround.](https://stackoverflow.com/a/51737984/6838025) – leonard chan Feb 01 '19 at 18:31
  • Possible duplicate of [Autoplay background video in Chrome Autoplay Policy](https://stackoverflow.com/questions/50465231/autoplay-background-video-in-chrome-autoplay-policy) – zero298 Feb 01 '19 at 19:44

1 Answers1

0

I know this is old, but I just had issues and wanted to post. It looks like the file size needs to be around 2MB max for the autoplay function to work for a background video. I just spent all morning with the correct code, testing in chrome, but it wouldn't play until I got the file size to 2.1MB, so I would say max is probably around 2.5MB.

Rion
  • 1
  • Actually the answer seems to be more complex: These are as far as I know the current rules: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes – Pauloco May 16 '20 at 22:20