From a57448a41155ad8800960a8ced53d7c675dcc906 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 15 Jun 2024 13:57:23 +0200 Subject: [PATCH] feat: show volume after changing via shortcut --- src/components/VideoPlayer.vue | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/VideoPlayer.vue b/src/components/VideoPlayer.vue index 1e41125c..b3650093 100644 --- a/src/components/VideoPlayer.vue +++ b/src/components/VideoPlayer.vue @@ -40,6 +40,14 @@ +
+ + + +
@@ -95,6 +103,8 @@ export default { showSpeedModal: false, showCurrentSpeed: false, hideCurrentSpeed: null, + showCurrentVolume: false, + hideCurrentVolume: null, playbackSpeedInput: null, currentTime: 0, seekbarPadding: 2, @@ -167,11 +177,11 @@ export default { e.preventDefault(); break; case "up": - videoEl.volume = Math.min(videoEl.volume + 0.05, 1); + self.adjustPlaybackVolume(videoEl.volume + 0.05); e.preventDefault(); break; case "down": - videoEl.volume = Math.max(videoEl.volume - 0.05, 0); + self.adjustPlaybackVolume(videoEl.volume - 0.05); e.preventDefault(); break; case "left": @@ -693,6 +703,14 @@ export default { this.showCurrentSpeed = true; this.hideCurrentSpeed = window.setTimeout(() => (this.showCurrentSpeed = false), 1500); }, + adjustPlaybackVolume(newVolume) { + const normalizedVolume = Math.min(1, Math.max(0, newVolume)); + this.$refs.videoEl.volume = normalizedVolume; + if (this.hideCurrentVolume) window.clearTimeout(this.hideCurrentVolume); + this.showCurrentVolume = false; + this.showCurrentVolume = true; + this.hideCurrentVolume = window.setTimeout(() => (this.showCurrentVolume = false), 1500); + }, setSpeedFromInput() { try { const newSpeed = Number(this.playbackSpeedInput);