Skip to content

Commit

Permalink
fix(player): auto focus player when video canplay
Browse files Browse the repository at this point in the history
Co-authored-by: lainio24 <[email protected]>
  • Loading branch information
WakelessSloth56 and lainio24 committed Mar 13, 2024
1 parent 02c2425 commit c94f34c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/player.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class Player {
this.options.fullscreen ? this.requestFullscreen() : this.setContainerData('fullscreen', false);
}
this.#constructed = true;
if (this.options.autoPlay) this.toast('Autoplay');
if (this.options.autoPlay) {
this.toast('Autoplay');
}
this.focus();
}

Expand All @@ -77,6 +79,7 @@ class Player {
this.setContainerData('paused', this.video.paused);
this.#overHour = this.video.duration >= 60 * 60;
});
this.onVideoEvent('canplay', () => this.focus());
this.onVideoEvent('play', () => this.setContainerData('paused', this.video.paused));
this.onVideoEvent('pause', () => this.setContainerData('paused', this.video.paused));
this.onVideoEvent('volumechange', () => this.setContainerData('muted', this.video.muted));
Expand All @@ -85,18 +88,16 @@ class Player {
this.setContainerData('fullscreen', fullscreen ? true : false);
this.firePlayerEvent(fullscreen ? 'fullscreen' : 'fullscreenexit');
});
{
new ResizeObserver(() => {
this.video.dispatchEvent(
new CustomEvent('resize', {
detail: {
width: this.video.offsetWidth,
height: this.video.offsetHeight,
},
})
);
}).observe(this.video);
}
new ResizeObserver(() => {
this.video.dispatchEvent(
new CustomEvent('resize', {
detail: {
width: this.video.offsetWidth,
height: this.video.offsetHeight,
},
})
);
}).observe(this.video);
bindMetaEvent(this.container, this.#metadata.playerEvent, this);
bindMetaEvent(this.video, this.#metadata.videoEvent, this, this.video);
}
Expand Down

0 comments on commit c94f34c

Please sign in to comment.