html - 视频无法在 chrome 中播放或自动播放,甚至静音 - 有时是,有时不是
问题描述
我找不到解决方案。很抱歉把 angular 和 html 作为标签 - 这是因为我不知道谁是有罪的。
是的,我在 Stack Overflow 和许多其他来源看到“静音”视频基本上没有限制。但在我的场景中......好吧,有时它有效,有时它不起作用......有时我刷新并且它有效。
很随意。
<video *ngIf="p.background.type==='video'" [ngStyle]="{opacity: p.background.backgroundOpacity}"
class="backgroundElement" src="../assets/backgrounds/videos/{{p.background.file}}"
[ngClass]="{currentVideo: i === this.pageIndex}"
muted loop></video>
const video = this.elRef.nativeElement.querySelector('.currentVideo').play();
if (video !== undefined) {
video.then(_ => {
console.log('worked at this time');
}).catch(error => {
console.log(error);
});
}
}, 2000);
我从 Promise 得到的错误是:消息:“play() 失败,因为用户没有先与文档交互。”
但这是一个静音视频。那么,有什么建议吗?
解决方案
推荐阅读
- javascript - 启用屏幕阅读器时,键盘选项卡不起作用
- python - pytorch在模型或层中转发期间如何计算macs和参数?
- core-data - 如何在 SwiftUI 中对 CoreData 关系使用选择器
- rsync - rsync 选项 --update 和 --append-verify
- python - 如何在df中垂直应用函数
- reactjs - 为我的应用程序实现了一个搜索页面,并尝试复制亚马逊搜索页面。使用反应 /universal-router/apollo-graphql
- apache-spark - 带有文件扩展名的 Spark saveAsTextFile
- ruby-on-rails - 在 AWS Cloud9 (c9) 中使用 PostgreSQL 设置 Rails 6
- webpack - Webpack 5 警告:'require.extensions 不受 webpack 支持。改用装载机。
- laravel - 在laravel 8 vue3惯性js上设置ziggy后,app.blade.php中无法识别@route