这是我的player.component.html
<video width="320" height="240" autoplay autobuffer [src]="videoSrc" (ended)="videoEnd()">
Your browser does not support the video tag.
</video>
<button (click)="pauseOrPlay()">pause/play</button>
在我的player.component.ts中,我有以下函数,当视频结束或单击按钮时调用
videoEnd(event) {
console.log("video ended");
}
pauseOrPlay(event){
console.log("button clicked");
//pause or resume video here
}
我现在想要的是,当单击按钮时,暂停或恢复视频。我可以使用 vid.play() 或 vid.pause() 在 javascript 中执行此操作,但我找不到在 angular2 中执行此操作的方法。如有任何建议,我们将不胜感激。
最佳答案
也许您可以在 video
标记内存储一个 localvariable
并将其传递给暂停函数。
<video #video> </video>
<button (click)="pauseOrPlay(video)">pause/play</button>
pauseOrPlay(video){
video.pause();
}
关于angular - 如何从angular2中的函数调用视频暂停事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41877688/