From a71fc40b5d0eb32eace1fa5c7e083baeafdc6a6e Mon Sep 17 00:00:00 2001 From: PizZaKatZe Date: Wed, 29 Sep 2021 17:36:17 +0200 Subject: [PATCH] Fix volume slider UI updates --- .../AudioManager/AudioManager.svelte | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/front/src/Components/AudioManager/AudioManager.svelte b/front/src/Components/AudioManager/AudioManager.svelte index 3253699e..4422d002 100644 --- a/front/src/Components/AudioManager/AudioManager.svelte +++ b/front/src/Components/AudioManager/AudioManager.svelte @@ -12,15 +12,12 @@ let unsubscriberFileStore: Unsubscriber | null = null; let unsubscriberVolumeStore: Unsubscriber | null = null; - let volume: number = 1; let decreaseWhileTalking: boolean = true; onMount(() => { - volume = localUserStore.getAudioPlayerVolume(); + let volume = Math.min(localUserStore.getAudioPlayerVolume(), get(audioManagerVolumeStore).volume); + audioManagerVolumeStore.setVolume(volume); audioManagerVolumeStore.setMuted(localUserStore.getAudioPlayerMuted()); - changeVolume(); - - loadAudioSettings(); unsubscriberFileStore = audioManagerFileStore.subscribe(() => { HTMLAudioPlayer.pause(); @@ -40,6 +37,7 @@ HTMLAudioPlayer.volume = audioManager.volume; HTMLAudioPlayer.muted = audioManager.muted; HTMLAudioPlayer.loop = audioManager.loop; + updateVolumeUI(); }); }); @@ -52,11 +50,12 @@ } }); - function changeVolume() { + function updateVolumeUI() { if (get(audioManagerVolumeStore).muted) { audioPlayerVolumeIcon.classList.add("muted"); audioPlayerVol.value = "0"; } else { + let volume = HTMLAudioPlayer.volume; audioPlayerVol.value = "" + volume; audioPlayerVolumeIcon.classList.remove("muted"); if (volume < 0.3) { @@ -75,21 +74,14 @@ const muted = !get(audioManagerVolumeStore).muted; audioManagerVolumeStore.setMuted(muted); localUserStore.setAudioPlayerMuted(muted); - changeVolume(); - } - - function loadAudioSettings() { - audioManagerVolumeStore.setVolume(localUserStore.getAudioPlayerVolume()); - audioManagerVolumeStore.setMuted(localUserStore.getAudioPlayerMuted()); } function setVolume() { - volume = parseFloat(audioPlayerVol.value); + let volume = parseFloat(audioPlayerVol.value); audioManagerVolumeStore.setVolume(volume); localUserStore.setAudioPlayerVolume(volume); audioManagerVolumeStore.setMuted(false); localUserStore.setAudioPlayerMuted(false); - changeVolume(); } function disallowKeys() {