Chrome中的自动播放静音功能仍无法正常工作 [英] Muted Autoplay in Chrome still not working

查看:205
本文介绍了Chrome中的自动播放静音功能仍无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让chrome自动播放视频.我已将视频设置为静音,并且它可以在Safari和Firefox中自动播放,但不能在chrome中播放.

I am having trouble getting chrome to autoplay a video. I have set the video to muted and it auto plays in both Safari and Firefox but not chrome.

            <video autoplay muted poster="path to video" id="bgvid">

        <source src="assets/uploads/hero/livePhotoNoSound.mp4" type="video/webm">

            <source src="assets/uploads/hero/livePhotoNoSound.mp4" type="video/mp4">

        </video>    

我想视频自动开始播放.目前,视频已加载,但仍处于静止状态.我读过的所有内容都说,只要将它静音,它就可以播放,但这不是我得到的结果.

I want to video to start playing automatically. Currently the video loads, but is just still. Everything I've read says that as long as it's muted it should play, but that is not the result I'm getting.

推荐答案

尽管@ richard-lindner的解决方案对我不起作用,但它使我走上了正轨.

Although @richard-lindner's solution didn't work for me, it put me on the right track.

在我的情况下,尽管存在muted属性,但Chrome会忽略它,并且会以静默方式失败,除非也已在javacript中明确设置了该属性,例如

In my case, although the muted attribute was present, Chrome was ignoring it and failing silently unless it was also explicitly set in javacript e.g.

var video = document.getElementById("myVideo");
video.oncanplaythrough = function() {
    video.muted = true;
    video.play();
}

有趣的是,使用javascript强制自动播放,但省略video.muted = true行确实在控制台中显示了自动播放策略错误,这表明Chrome浏览器确实在某些情况下忽略了muted属性.在我看来,这就像是Chrome的自动播放政策存在的错误.

Interestingly, forcing the autoplay using javascript but ommitting the video.muted = true line did display the autoplay policy error in the console, suggesting Chrome is indeed ignoring the muted attribute in some cases. This to me feels like a bug with Chrome's autoplay policy.

请注意,仅当未缓存视频时才会发生错误.如果已缓存,则自动播放将按预期工作.

Note that the error occurred only when the video was not cached. If it was cached, autoplay worked as expected.

这篇关于Chrome中的自动播放静音功能仍无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆