Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在AfterViewChecked上播放视频_Javascript_Angular_Typescript - Fatal编程技术网

Javascript 在AfterViewChecked上播放视频

Javascript 在AfterViewChecked上播放视频,javascript,angular,typescript,Javascript,Angular,Typescript,在Angular 9中,我想在AfterViewChecked生命周期内自动播放多个视频 这是我的组件代码: import { AfterViewChecked, Component, ElementRef, ViewChild, } from "@angular/core"; @Component({ selector: "app-root", templateUrl: "./app.component.html&qu

在Angular 9中,我想在AfterViewChecked生命周期内自动播放多个视频

这是我的组件代码:

import {
  AfterViewChecked,
  Component,
  ElementRef,
  ViewChild,
} from "@angular/core";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.scss"],
})
export class AppComponent implements AfterViewChecked {
  @ViewChild("videoPlayer") videoPlayer: ElementRef;

  private index = 0;
  private videoList = [
    "../assets/Background_Videos/FoodPack1_01_Videvo.webm",
    "../assets/Background_Videos/FoodPack1_03_Videvo.webm",
    "../assets/Background_Videos/FoodPack1_12_Videvo.webm",
  ];

  ngAfterViewChecked(): void {
    this.playVideo();
  }

  videoEnded() {
    if (this.index == this.videoList.length - 1) {
      this.index = 0;
    } else {
      this.index++;
    }
    this.playVideo();
  }

  playVideo() {
    this.videoPlayer.nativeElement.src = this.videoList[this.index];
    this.videoPlayer.nativeElement.load();
    this.videoPlayer.nativeElement.muted = true;
    this.videoPlayer.nativeElement.play();
  }
}
和html:

<video #videoPlayer (ended)="videoEnded()" width="400px"></video>   

此视频自动播放,但在控制台中接收错误:

我不明白,我的代码哪一部分出错了?

(结束)
可能一开始就被触发了。可能需要清理url吗?