我花了很多时间试图弄清楚为什么视频会像这样嵌入:

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

一旦页面在FireFox中加载,就开始自动播放,但不能在基于Webkit的浏览器中自动播放。这只发生在一些随机的页面上。到目前为止我还没有找到原因。我怀疑一些未关闭的标签或CMS编辑器创建的大量JS。


当前回答

我能得到的最好的修复是在</video>之后添加这段代码

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

...虽然不漂亮,但还是管用的。

更新 最近许多浏览器只能自动播放视频的声音关闭,所以你需要添加静音属性的视频标签

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

其他回答

请在自动播放单词前使用静音关键字,这里有一些隐私在2018年4月的变化。 你可以在这里阅读政策

对于angular,你必须静音它,并像下面这样在ngAfterViewInit()中播放它

<video height="256" loop autoplay muted controls id="vid" #videoRef>
         <source type="video/mp4" src="video_file.mp4"></source>
         <source type="video/ogg" src="video_file.ogg"></source>
</video>
 ​@ViewChild('videoRef', { static: true }) videoRef!: ElementRef

​ngAfterViewInit(): void {
  ​const media = this.videoRef.nativeElement
  ​media.muted = true 
  ​media.play() 
​ } 

在页面底部添加以下代码对我来说很有效。我不知道它为什么有效:(

 setTimeout(function(){
     document.getElementById('vid').play();
 },1000);

我把我的声音调成静音自动播放。 我认为谷歌规则不会让chrome自动播放,除非它是静音的。

<video id="video" controls autoplay muted
        border:0px solid black;"
        width="300"
        height="300">
    <source src="~/Videos/Lumen5_CTAS_Home2.mp4"
            type="video/mp4" />
    Your browser does not support the video tag.
    Please download the mp4 plugin to see the CTAS Intro.
</video>

在使用jQuery play()或DOM操作后,根据其他答案的建议,它仍然不能工作(视频不能自动播放)在Chrome for Android(版本56.0)。

根据developers.google.com上的这篇文章,从Chrome 53开始,如果视频被静音,浏览器会尊重自动播放选项。

因此,在视频标签中使用自动播放静音属性可以使视频在Chrome浏览器中自动播放。

摘自上述链接:

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.