javascript - Video auto play is not working in Safari and Chrome desktop browser

ID : 20047

viewed : 14

Tags : javascripthtmlgoogle-chromesafariwebkitjavascript

Top 5 Answer for javascript - Video auto play is not working in Safari and Chrome desktop browser

vote vote

93

The best fix I could get was adding this code just after the </video>

<script>     document.getElementById('vid').play(); </script> 

...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 too

<video autoplay muted> ... </video> 
vote vote

85

After using jQuery play() or DOM maniupulation as suggested by the other answers, it was not still working (Video wasn't autoplaying) in the Chrome for Android (Version 56.0).

As per this post in developers.google.com, From Chrome 53, the autoplay option is respected by the browser, if the video is muted.

So using autoplay muted attributes in video tag enables the video to be autoplayed in Chrome browsers from version 53.

Excerpt from the above link:

Muted autoplay for video is supported by Chrome for Android as of version 53. Playback will start automatically for a video element once it comes into view if both autoplay and muted are set[...]

<video autoplay muted>     <source src="video.webm" type="video/webm" />     <source src="video.mp4" type="video/mp4" /> </video> 
  • Muted autoplay is supported by Safari on iOS 10 and later.
  • Autoplay, whether muted or not, is already supported on Android by Firefox and UC Browser: they do not block any kind of autoplay.
vote vote

79

Google just changed their policy for autoplay videos, it has to be muted

You can check here

so just add muted

<video height="256" loop="true" autoplay="autoplay" controls="controls" id="vid" muted>          <source type="video/mp4" src="video_file.mp4"></source>          <source type="video/ogg" src="video_file.ogg"></source> </video> 
vote vote

61

It happens that Safari and Chrome on Desktop do not like DOM manipulation around the video tag. They will not fire the play order when the autoplay attribute is set even if the canplaythrough event has fired when the DOM around the video tag has changed after initial page load. Basically I had the same issue until I deleted a .wrap() jQuery around the video tag and after that it autoplayed as expected.

vote vote

53

For me the issue was that the muted attribute needed to be added within the video tag. I.e.:

<video width="1920" height="1980" src="video/Night.mp4" type="video/mp4" frameborder="0" allowfullscreen autoplay loop muted></video>` 

Top 3 video Explaining javascript - Video auto play is not working in Safari and Chrome desktop browser

Related QUESTION?