Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

currentTime getter always returns 0 #62

Open
jhayg12 opened this issue Oct 12, 2020 · 2 comments
Open

currentTime getter always returns 0 #62

jhayg12 opened this issue Oct 12, 2020 · 2 comments

Comments

@jhayg12
Copy link

jhayg12 commented Oct 12, 2020

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);
}
@KangHidro
Copy link

You may try:

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

@freitas-patrick
Copy link

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);
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants