diff --git a/src/utils/player.ts b/src/utils/player.ts index 9077c6ca..a3c09a05 100644 --- a/src/utils/player.ts +++ b/src/utils/player.ts @@ -11,6 +11,9 @@ export class PlayerClass { const { duration: total, currentTime: current } = this.element; const progress = (current / total) * 100; + this.current = current || 0; + this.total = total || 0; + this.element.dispatchEvent( new CustomEvent('playprogress', { detail: { current, total, progress }, @@ -19,6 +22,10 @@ export class PlayerClass { }); } + public current: number = 0; + + public total: number = 0; + public element: HTMLAudioElement = new Audio(); public duration: number = 0; @@ -46,6 +53,14 @@ export class PlayerClass { public getDuration = () => { return this.element.currentTime; }; + + public jumpToTime = (time: number) => { + this.element.currentTime = time; + }; + + public jumpToPercent = (percent: number) => { + this.element.currentTime = (this.total * percent) / 100; + }; } const Player = new PlayerClass();