I spent quite a lot of time trying to figure out why video embedded like here:
<video height="256" loop autoplay muted controls id="vid">
<source type="video/mp4" src="video_file.mp4"></source>
<source type="video/ogg" src="video_file.ogg"></source>
</video>
starts playing automatically once the page is loaded in FireFox but cannot do autoplay in Webkit based browsers. This only happened on some random pages. So far I was unable to find the cause. I suspect some unclosed tags or extensive JS created by CMS editors.
Adding the below code at the bottom of the page worked for me . I dont know why it works :(
None of the other answers worked for me. My workaround was to trigger a click on the video itself; hacky (because of the timeout that is needed) but it works fine:
I solved the same problem with,
You have to launch the videos after the page has been shown.
The best fix I could get was adding this code just after the
</video>
...not pretty but somehow works.
UPDATE Recently many browsers can only autoplay the videos with sound off, so you'll need to add
muted
attribute to the video tag toovar video = document.querySelector('video'); video.muted = true; video.play()
Only this solution helped me,
<video autoplay muted ...>...</video>
didn't work...I started out with playing all the visible videos, but old phones weren't performing well. So right now I play the one video that's closest to the center of the window and pause the rest. Vanilla JS. You can pick which algorithm you prefer.