From 566ea569e1fcdebf9744af521e3e62c2bfcc1be0 Mon Sep 17 00:00:00 2001 From: Jan-Marlon Leibl Date: Thu, 15 May 2025 14:14:18 +0200 Subject: [PATCH] refactor(audio.service): improve audio caching logic --- frontend/src/app/shared/services/audio.service.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/shared/services/audio.service.ts b/frontend/src/app/shared/services/audio.service.ts index 5e716fb..db44378 100644 --- a/frontend/src/app/shared/services/audio.service.ts +++ b/frontend/src/app/shared/services/audio.service.ts @@ -7,12 +7,13 @@ export class AudioService { private audioCache = new Map(); private getAudio(soundName: string): HTMLAudioElement { - if (!this.audioCache.has(soundName)) { - const audio = new Audio(`/sounds/${soundName}`); - this.audioCache.set(soundName, audio); - return audio; + if (this.audioCache.has(soundName)) { + return this.audioCache.get(soundName)!; } - return this.audioCache.get(soundName)!; + + const audio = new Audio(`/sounds/${soundName}.mp3`); + this.audioCache.set(soundName, audio); + return audio; } playBetSound(): void {