首页 > 解决方案 > 使用 HTMLVideoElement 时如何暂停视频

问题描述

这是我的html代码

<mat-carousel timings="250ms ease-in" [autoplay]="false" interval="5000" color="accent" maxWidth="93%"
                proportion="80" slides="3" [loop]="true" [hideArrows]="false" [hideIndicators]="false" [useKeyboard]="true"
                [useMouseWheel]="false" orientation="ltr" (change)="currentSlideIndex = $event">
                <mat-carousel-slide #matCarouselSlide *ngFor="let slide of video; let i = index"
                  overlayColor="#00000040" [hideOverlay]="false">
                  <video controls class="videostyle" #videoPlayer id='myvideoelement'>
                    <source *ngIf="slide.Video" src="{{slide?.Video}}" type="video/mp4">
                    Browser not supported
                  </video>
                  <button (click)="toggleVideo(videoPlayer)">Play/Pause</button>
                </mat-carousel-slide>
                <br>
              </mat-carousel>
      <button (click)="toggleVideo1($event)">bydiv</button>

在 ts 我有这个功能:

toggleVideo(videoplayer) {
    console.log(videoplayer)
    videoplayer.pause();
  }
  toggleVideo1(e) {
    let video = <HTMLVideoElement>document.getElementById('myvideoelement');
    video.pause();
      }

从这两个功能我得到相同的控制台,但只toggleVideo(videoplayer)暂停视频。

请你能与我分享任何想法,谁有问题?如何使它工作 toggleVideo1(e)

标签: angulartypescript

解决方案


推荐阅读