Autoplay of HTML5 video doesn't work

六眼飞鱼酱① 提交于 2019-12-24 04:24:04

问题


I am not sure why autoplay function doesn't work on site. Live site- http://lyorcohen.searchinteractions.com/ComingSoon/

<video class="supervideo hidden-phone hidden-tablet" poster="images/stillframe.jpg" autoplay>
<source src="video/WeaveLogo.mov" />
Your browser does not support the HTML5 video tag. Please upgrade it.
</video>

回答1:


Works in Chrome but not in Firefox.

You also get this error in Firefox when the MP4 fails (due to testing this on an XP machine which does not support mp4 with Firefox):

HTTP load failed with status 404. Load of media resource http://lyorcohen.searchinteractions.com/ComingSoon/video/WeaveLogo.ogg failed.

which means the fall-back fails due to the ogg file gone missing. Check that the file actually is there and that the name is spelled the same including capitalization.

On Chrome the MP4 video auto-plays and works fine.

You could also consider to provide a webm version of the file.

To eliminate further possible causes you can provide the type attribute in your source tags:

<source src="video/WeaveLogo.webm" type="video/webm" />

You are using the autoplay attribute correctly but some peculiar browsers has historically had problems with attributes without values so you can add =true to it to make these browsers happy (I can only think about one browser though...).




回答2:


I've had similar problem when adding a video on a Magento site. It seems that when I used the preload attribute before the autoplay attribute, it fixed the problem. Was testing in Chrome




回答3:


var vid = document.getElementById("myVideo");
vid.autoplay = true;
vid.load();



回答4:


Most browsers require the video to be initiated by the user or muted.

Try:

<video class="supervideo hidden-phone hidden-tablet" poster="images/stillframe.jpg" muted="muted" autoplay>
<source src="video/WeaveLogo.mov" />
Your browser does not support the HTML5 video tag. Please upgrade it.
</video>


来源:https://stackoverflow.com/questions/19482741/autoplay-of-html5-video-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!