javascript - Inline-videos don't play when direct URLs are pasted into URL bar in Google Chrome
问题描述
If I link from another page in my site, they play. They look like this:
<video playsinline autoplay loop class="vf-video">
<source src="/assets/video/the-video.mp4" type="video/mp4">
</video>
When I paste in the URL and hit enter, they do not play. I even added this jQuery in a DOMContentLoaded
listener:
setTimeout(function () {
$("video[autoplay]").each(function () {
console.log(this);
this.play();
});
}, 3000);
Still will not play. They play fine in FireFox. Using latest Google Chrome on OS X.
解决方案
For video elements without sound disabled, they wont play without a user interaction. A click from a previous page is apparently considered a user interaction that should allow video to play. For my example, I just had to add the 'muted' to meet this criteria so the video would autoplay.
推荐阅读
- javascript - 如何使用 CSS 关键帧添加翻牌动画?
- reactjs - 构建 Gatsby 网站时出错:未定义窗口
- gnuplot - Gnuplot。轴和边界上的抽动。仅在边框上编号
- python - 如何使用 Dash 实现动态链式下拉菜单?(即第二列的选项取决于第一列的输入)
- reactjs - 访问从 GraphQL 生成的多个嵌套 TypeScript 类型
- flutter - Flutter Navigator 2.0:带抽屉导航的命名路由
- rest - REST API 是否有 CompareAndSet 或 Compare-and-swap (CAS) 等效项?
- javascript - React Redux,尝试将产品添加到购物车
- android - Flutter SDK 已安装,但未找到(Windows) - 已解决
- python - 将两个不同大小的数据帧中的数据相乘并保留不相似的数据