From 6d9a3f45dc4691fceb5561723998fc336161f077 Mon Sep 17 00:00:00 2001 From: Valdo Date: Mon, 21 Mar 2022 15:22:51 +0000 Subject: [PATCH] Allow audio (#1991) * Removing old unused images Just a bit of cleanup! * Allow audio feature * Pretty * Ignored screenshot folder * Added manual test * Simplified test map Co-authored-by: Valdo Romao --- .../AudioManager/AudioManager.svelte | 118 ++++----- .../Components/Menu/SettingsSubMenu.svelte | 17 ++ front/src/Connexion/LocalUserStore.ts | 7 + front/src/i18n/de-DE/audio.ts | 3 +- front/src/i18n/en-US/audio.ts | 3 +- front/src/i18n/fr-FR/audio.ts | 3 +- maps/assets/audio/campfire.ogg | Bin 0 -> 1778217 bytes maps/tests/AllowAudio/map.json | 241 ++++++++++++++++++ maps/tests/index.html | 8 + tests/.gitignore | 1 + 10 files changed, 341 insertions(+), 60 deletions(-) create mode 100755 maps/assets/audio/campfire.ogg create mode 100644 maps/tests/AllowAudio/map.json diff --git a/front/src/Components/AudioManager/AudioManager.svelte b/front/src/Components/AudioManager/AudioManager.svelte index eec51572..786c5693 100644 --- a/front/src/Components/AudioManager/AudioManager.svelte +++ b/front/src/Components/AudioManager/AudioManager.svelte @@ -13,20 +13,20 @@ let unsubscriberFileStore: Unsubscriber | null = null; let unsubscriberVolumeStore: Unsubscriber | null = null; - let decreaseWhileTalking: boolean = true; + let isAudioAllowed: boolean = true; onMount(() => { let volume = Math.min(localUserStore.getAudioPlayerVolume(), get(audioManagerVolumeStore).volume); audioManagerVolumeStore.setVolume(volume); audioManagerVolumeStore.setMuted(localUserStore.getAudioPlayerMuted()); - unsubscriberFileStore = audioManagerFileStore.subscribe((src) => { + unsubscriberFileStore = audioManagerFileStore.subscribe((src: string) => { HTMLAudioPlayer.pause(); HTMLAudioPlayer.src = src; HTMLAudioPlayer.loop = get(audioManagerVolumeStore).loop; HTMLAudioPlayer.volume = get(audioManagerVolumeStore).volume; HTMLAudioPlayer.muted = get(audioManagerVolumeStore).muted; - void HTMLAudioPlayer.play(); + tryPlay(); }); unsubscriberVolumeStore = audioManagerVolumeStore.subscribe((audioManager: audioManagerVolume) => { const reduceVolume = audioManager.talking && audioManager.decreaseWhileTalking; @@ -52,6 +52,16 @@ } }); + function tryPlay() { + void HTMLAudioPlayer.play() + .then(() => { + isAudioAllowed = true; + }) + .catch(() => { + isAudioAllowed = false; + }); + } + function updateVolumeUI() { if (get(audioManagerVolumeStore).muted) { audioPlayerVolumeIcon.classList.add("muted"); @@ -90,73 +100,67 @@ audioPlayerVol.blur(); return false; } - - function setDecrease() { - audioManagerVolumeStore.setDecreaseWhileTalking(decreaseWhileTalking); - }
-
- - - - +
+
+ + - - - - - - - - - - -
-
- + + + + + + + + + + + + +
+
+ +