From 17e1ddad9c20e12ce35f2a0d8661feb8130046d2 Mon Sep 17 00:00:00 2001 From: Erik Date: Thu, 10 Mar 2022 10:15:06 +0100 Subject: [PATCH] fix: re-set loading state if loading new data into the same video element --- src/VideoEventFilter.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/VideoEventFilter.ts b/src/VideoEventFilter.ts index 8e6a768..45b60f8 100644 --- a/src/VideoEventFilter.ts +++ b/src/VideoEventFilter.ts @@ -46,6 +46,7 @@ export class VideoEventFilter extends EmitterBaseClass { } private setupEventListeners(): void { + this.videoElement.addEventListener("loadstart", this.onLoading.bind(this)); this.videoElement.addEventListener("loadeddata", this.onLoaded.bind(this)); this.videoElement.addEventListener("playing", this.onPlaying.bind(this)); this.videoElement.addEventListener("pause", this.onPause.bind(this)); @@ -60,6 +61,12 @@ export class VideoEventFilter extends EmitterBaseClass { this.videoElement.addEventListener("ended", this.onEnded.bind(this)); } + private onLoading(): void { + if (this.state === PlayerState.Loading) return; + this.setState(PlayerState.Loading); + this.emit(PlayerEvents.Loading); + } + private onLoaded(): void { if (this.state === PlayerState.Loading) { this.emit(PlayerEvents.Loaded);