diff --git a/front/src/api/player.ts b/front/src/api/player.ts index 6a1ea4582..53c72d5a0 100644 --- a/front/src/api/player.ts +++ b/front/src/api/player.ts @@ -17,6 +17,7 @@ export interface Sound { readonly audioNode: IAudioNode readonly isErrored: Ref readonly isLoaded: Ref + readonly isDisposed: Ref readonly currentTime: number readonly playable: boolean readonly duration: number @@ -51,6 +52,7 @@ export class HTMLSound implements Sound { readonly isErrored = ref(false) readonly isLoaded = ref(false) + readonly isDisposed = ref(false) audioNode = createAudioSource(this.#audio) onSoundLoop: EventHookOn @@ -112,12 +114,15 @@ export class HTMLSound implements Sound { } async preload () { + this.isDisposed.value = false this.isErrored.value = false console.log('CALLING PRELOAD ON', this) this.#audio.load() } async dispose () { + if (this.isDisposed.value) return + // Remove all event listeners this.#scope.stop() @@ -128,6 +133,8 @@ export class HTMLSound implements Sound { // Cancel any request downloading the source this.#audio.src = '' this.#audio.load() + + this.isDisposed.value = true } async play () { diff --git a/front/src/composables/audio/queue.ts b/front/src/composables/audio/queue.ts index 2f5afb3f5..f0eeb72e4 100644 --- a/front/src/composables/audio/queue.ts +++ b/front/src/composables/audio/queue.ts @@ -324,7 +324,7 @@ export const useQueue = createGlobalState(() => { const clear = async () => { await currentSound.value?.pause() await currentSound.value?.seekTo(0) - currentSound.value?.dispose() + await currentSound.value?.dispose() clearRadio.value = true diff --git a/front/src/composables/audio/tracks.ts b/front/src/composables/audio/tracks.ts index 5490ee591..95b1214bb 100644 --- a/front/src/composables/audio/tracks.ts +++ b/front/src/composables/audio/tracks.ts @@ -101,6 +101,11 @@ export const useTracks = createGlobalState(() => { setTimeout(() => playNext(), 0) }) + // NOTE: When the sound is disposed, we need to delete it from the cache (#2157) + whenever(sound.isDisposed, () => { + soundCache.delete(track.id) + }) + // NOTE: Bump current track to ensure that it lives despite enqueueing 3 tracks as next track: // // In every queue we have 3 tracks that are cached, in the order, they're being played: