ngx-plyr icon indicating copy to clipboard operation
ngx-plyr copied to clipboard

currentTime getter always returns 0

Open jhayg12 opened this issue 4 years ago • 2 comments

Hi there,

I'm trying to get the currentTime value of the video that was currently playing on pause event but it always returns 0.

@ViewChild(PlyrComponent) plyr: PlyrComponent;

videoPlayer: Plyr;

pause(event: Plyr.PlyrEvent) {
  console.log(this.videoPlayer.currentTime);
}

jhayg12 avatar Oct 12 '20 01:10 jhayg12

You may try:

@ViewChild(PlyrComponent, { static: true }) plyr: PlyrComponent;
// videoPlayer: Plyr; // is not needed
...
this.plyr.player.currentTime
...

KangHidro avatar Oct 12 '20 07:10 KangHidro

I had the same issue, and guess that in some moment's the player isn't avaliable, therefore the currentTime is always 0.

I realized that has two methods that are executed in moments where the currentTime property are filled, are they:

// on html
<plyr (plyrInit)="initPlyr($event)" (plyrPlay)="played($event)"></plyr>
// on typescript
@ViewChild(PlyrComponent)
plyr!: PlyrComponent;
player!: Plyr;

var _this = this;
initPlyr(event: any) {
   this.player.on('timeupdate', (event) => {
      console.log(_this.player.currentTime);
   }
}

played(event: Plyr.PlyrEvent) {
    console.log(this.player.currentTime);
}

freitas-patrick avatar Dec 18 '20 17:12 freitas-patrick