2017-08-13 92 views
0

我有一个使用HTML5在页面中显示的视频列表,但我想要的是当我播放一个时,其他人应该停止/暂停。播放HTML 5视频并阻止其他人

我正在使用Angular 2 TypeScript。

<video controls (click)="toggleVideo()" #videoPlayer> 
    <source class="embed-responsive-item" src="{{ video.url }}" type="video/mp4" /> 
       Browser not supported 
</video> 
@ViewChild('videoPlayer') videoplayer: any; 

toggleVideo(event: any) { 
    this.videoplayer.nativeElement.play(); 
} 

回答

0

查询所有使用@ViewChildren装饰在页面上的视频。点击后,暂停所有视频并播放点击的视频(就像您已经在做的那样)。

要查询所有视频,请使用选择器'video'创建一个虚拟指令。然后使用此伪指令作为参数@ViewChildren,并确保读取ElementRef而不是指令实例(这将是默认值)。

@ViewChildren(VideoDirective, {read: ElementRef}) 
public videos: QueryList<ElementRef>