diff --git a/src/ui/BaseUI.ts b/src/ui/BaseUI.ts index 9a72019..4316fbc 100644 --- a/src/ui/BaseUI.ts +++ b/src/ui/BaseUI.ts @@ -6,11 +6,13 @@ */ import { VP } from "../core"; +import { EventManager } from "../events"; export class BaseUI { private player: VP; private video: HTMLVideoElement; private prefixClass: string; + private events: EventManager; private wrapper!: HTMLElement; private controlsWrap!: HTMLElement; private originalParent!: Node; @@ -20,6 +22,7 @@ export class BaseUI { this.player = player; this.video = video; this.prefixClass = prefixClass; + this.events = new EventManager(); this.build(); this.createPlayButton(); } @@ -51,6 +54,7 @@ export class BaseUI { destroy(): void { this.originalParent.insertBefore(this.video, this.nextSibling); this.wrapper.remove(); + this.events.removeAll(); } private createPlayButton(): void { @@ -62,10 +66,10 @@ export class BaseUI { playButton.innerText = "pause"; } - this.video.addEventListener("play", function (): void { + this.events.add(this.video, "play", function (): void { playButton.innerText = "pause"; }); - this.video.addEventListener("pause", function (): void { + this.events.add(this.video, "pause", function (): void { playButton.innerText = "play"; });