解决play() failed because the user didn‘t interact with the document

3 min read

解决方案 1:将视频静音

要解决此错误,您必须将视频静音。您可以在 HTML 中使用以下代码。让我们看看这个:

<video loop muted autoplay id="videomain">
  <source src="videoname.mp4" type="video/mp4">
</video>

解决方案2:使用以下代码

您可以使用以下代码来解决您的问题:

playVideo() {
    const media = this.videoplayer.nativeElement;
    media.muted = true; // without this line it's not working although I have "muted" in HTML
    media.play();
}