nkoehler / mat-video

:tv: mat-video is an Angular 8/9+ video player using Material!
https://nkoehler.github.io/mat-video/
MIT License
91 stars 47 forks source link

Time event not working #58

Open Shivampio opened 4 years ago

Shivampio commented 4 years ago

PLEASE FILL THIS OUT IF YOU WANT HELP WITH AN ISSUE!

Bug, feature request, or proposal:

<mat-video #video [src]="src" title="My Tutorial Title" [(time)]="ctime" [autoplay]="true" [preload]="true" [download]="false" color="accent" spinner="spin">

TS:- ctime = 30;

What is the current behavior?

never stop on time given

What is the expected behavior?

Video need to be paused on selected time

What are the steps to reproduce?

Providing a StackBlitz reproduction is the best way to share your issue.
StackBlitz starter: https://goo.gl/wwnhMV

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Is there anything else I should know?

jboz commented 4 years ago

For me, the time setting as an output does not work (ok for input). It also doesn't work in the demo.

But I found this great solution :

ngAfterViewInit(): void {
  fromEvent(this.matVideo.getVideoTag(), 'timeupdate')
    .pipe(
      throttleTime(1000),
      map(() => Math.round(this.matVideo.getVideoTag().currentTime)),
      mergeMap(time => this.store.dispatch(new UpdateVideoViewTime(this.lesson._id, this.video._id, time))),
      takeUntil(this.destroy$)
    )
    .subscribe();
}