Merge pull request from workadventure-xce/fix/volumeSliderUI

Fix volume slider UI updates
This commit is contained in:
David Négrier 2021-12-07 09:20:55 +01:00 committed by GitHub
commit df700a8740
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,15 +12,12 @@
let unsubscriberFileStore: Unsubscriber | null = null; let unsubscriberFileStore: Unsubscriber | null = null;
let unsubscriberVolumeStore: Unsubscriber | null = null; let unsubscriberVolumeStore: Unsubscriber | null = null;
let volume: number = 1;
let decreaseWhileTalking: boolean = true; let decreaseWhileTalking: boolean = true;
onMount(() => { onMount(() => {
volume = localUserStore.getAudioPlayerVolume(); let volume = Math.min(localUserStore.getAudioPlayerVolume(), get(audioManagerVolumeStore).volume);
audioManagerVolumeStore.setVolume(volume);
audioManagerVolumeStore.setMuted(localUserStore.getAudioPlayerMuted()); audioManagerVolumeStore.setMuted(localUserStore.getAudioPlayerMuted());
changeVolume();
loadAudioSettings();
unsubscriberFileStore = audioManagerFileStore.subscribe(() => { unsubscriberFileStore = audioManagerFileStore.subscribe(() => {
HTMLAudioPlayer.pause(); HTMLAudioPlayer.pause();
@ -40,6 +37,7 @@
HTMLAudioPlayer.volume = audioManager.volume; HTMLAudioPlayer.volume = audioManager.volume;
HTMLAudioPlayer.muted = audioManager.muted; HTMLAudioPlayer.muted = audioManager.muted;
HTMLAudioPlayer.loop = audioManager.loop; HTMLAudioPlayer.loop = audioManager.loop;
updateVolumeUI();
}); });
}); });
@ -52,11 +50,12 @@
} }
}); });
function changeVolume() { function updateVolumeUI() {
if (get(audioManagerVolumeStore).muted) { if (get(audioManagerVolumeStore).muted) {
audioPlayerVolumeIcon.classList.add("muted"); audioPlayerVolumeIcon.classList.add("muted");
audioPlayerVol.value = "0"; audioPlayerVol.value = "0";
} else { } else {
let volume = HTMLAudioPlayer.volume;
audioPlayerVol.value = "" + volume; audioPlayerVol.value = "" + volume;
audioPlayerVolumeIcon.classList.remove("muted"); audioPlayerVolumeIcon.classList.remove("muted");
if (volume < 0.3) { if (volume < 0.3) {
@ -75,21 +74,14 @@
const muted = !get(audioManagerVolumeStore).muted; const muted = !get(audioManagerVolumeStore).muted;
audioManagerVolumeStore.setMuted(muted); audioManagerVolumeStore.setMuted(muted);
localUserStore.setAudioPlayerMuted(muted); localUserStore.setAudioPlayerMuted(muted);
changeVolume();
}
function loadAudioSettings() {
audioManagerVolumeStore.setVolume(localUserStore.getAudioPlayerVolume());
audioManagerVolumeStore.setMuted(localUserStore.getAudioPlayerMuted());
} }
function setVolume() { function setVolume() {
volume = parseFloat(audioPlayerVol.value); let volume = parseFloat(audioPlayerVol.value);
audioManagerVolumeStore.setVolume(volume); audioManagerVolumeStore.setVolume(volume);
localUserStore.setAudioPlayerVolume(volume); localUserStore.setAudioPlayerVolume(volume);
audioManagerVolumeStore.setMuted(false); audioManagerVolumeStore.setMuted(false);
localUserStore.setAudioPlayerMuted(false); localUserStore.setAudioPlayerMuted(false);
changeVolume();
} }
function disallowKeys() { function disallowKeys() {