From b21edbb64d8618d1701695ad925cdd644188394f Mon Sep 17 00:00:00 2001 From: Kasper Seweryn Date: Sun, 29 Jan 2023 00:04:09 +0100 Subject: [PATCH] fix: #2061 Part-of: --- front/src/composables/audio/player.ts | 9 ++++++++- front/src/composables/audio/tracks.ts | 25 ++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/front/src/composables/audio/player.ts b/front/src/composables/audio/player.ts index e69dc5d56..a149130bc 100644 --- a/front/src/composables/audio/player.ts +++ b/front/src/composables/audio/player.ts @@ -192,7 +192,14 @@ export const usePlayer = createGlobalState(() => { return sound.isErrored.value }) - const { start: startErrorTimeout, stop: stopErrorTimeout } = useTimeoutFn(() => playNext(), 3000, { immediate: false }) + const { start: startErrorTimeout, stop: stopErrorTimeout } = useTimeoutFn(() => { + if (looping.value !== LoopingMode.LoopTrack) { + return playNext() + } + + isPlaying.value = false + }, 3000, { immediate: false }) + watch(currentIndex, stopErrorTimeout) whenever(errored, startErrorTimeout) diff --git a/front/src/composables/audio/tracks.ts b/front/src/composables/audio/tracks.ts index 1e35b627e..13fc845db 100644 --- a/front/src/composables/audio/tracks.ts +++ b/front/src/composables/audio/tracks.ts @@ -109,6 +109,18 @@ export const useTracks = createGlobalState(() => { return soundPromise } + // Skip when errored + const { start: soundUnplayable, stop: abortSoundUnplayableTimeout } = useTimeoutFn(() => { + const { isPlaying, looping, LoopingMode } = usePlayer() + const { playNext } = useQueue() + + if (looping.value !== LoopingMode.LoopTrack) { + return playNext() + } + + isPlaying.value = false + }, 3000, { immediate: false }) + // Preload next track const { start: startPreloadTimeout } = useTimeoutFn(async (index) => { const { queue } = useQueue() @@ -118,7 +130,9 @@ export const useTracks = createGlobalState(() => { // Create track from queue const createTrack = async (index: number) => { - const { queue, currentIndex, playNext, hasNext } = useQueue() + abortSoundUnplayableTimeout() + + const { queue, currentIndex } = useQueue() if (queue.value.length <= index || index === -1) return console.log('LOADING TRACK', index) @@ -126,14 +140,7 @@ export const useTracks = createGlobalState(() => { const sound = await createSound(track) if (!sound.playable) { - setTimeout(() => { - if (hasNext.value && index !== queue.value.length - 1) { - return playNext(true) - } - - const { isPlaying } = usePlayer() - isPlaying.value = false - }, 3000) + soundUnplayable() return }