ngx-plyr
ngx-plyr copied to clipboard
currentTime getter always returns 0
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);
}
You may try:
@ViewChild(PlyrComponent, { static: true }) plyr: PlyrComponent;
// videoPlayer: Plyr; // is not needed
...
this.plyr.player.currentTime
...
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);
}