Skip to content

Commit

Permalink
fix: re-set loading state if loading new data into the same video ele…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
slowmove committed Mar 10, 2022
1 parent 78e2cf7 commit 17e1dda
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/VideoEventFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
Expand Down

0 comments on commit 17e1dda

Please sign in to comment.