Kasper Seweryn 2023-01-29 00:04:09 +01:00 committed by Georg krause
parent 9552fcd9a9
commit 4a656777e3
2 changed files with 24 additions and 10 deletions

View File

@ -192,7 +192,14 @@ export const usePlayer = createGlobalState(() => {
return sound.isErrored.value 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) watch(currentIndex, stopErrorTimeout)
whenever(errored, startErrorTimeout) whenever(errored, startErrorTimeout)

View File

@ -109,6 +109,18 @@ export const useTracks = createGlobalState(() => {
return soundPromise 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 // Preload next track
const { start: startPreloadTimeout } = useTimeoutFn(async (index) => { const { start: startPreloadTimeout } = useTimeoutFn(async (index) => {
const { queue } = useQueue() const { queue } = useQueue()
@ -118,7 +130,9 @@ export const useTracks = createGlobalState(() => {
// Create track from queue // Create track from queue
const createTrack = async (index: number) => { const createTrack = async (index: number) => {
const { queue, currentIndex, playNext, hasNext } = useQueue() abortSoundUnplayableTimeout()
const { queue, currentIndex } = useQueue()
if (queue.value.length <= index || index === -1) return if (queue.value.length <= index || index === -1) return
console.log('LOADING TRACK', index) console.log('LOADING TRACK', index)
@ -126,14 +140,7 @@ export const useTracks = createGlobalState(() => {
const sound = await createSound(track) const sound = await createSound(track)
if (!sound.playable) { if (!sound.playable) {
setTimeout(() => { soundUnplayable()
if (hasNext.value && index !== queue.value.length - 1) {
return playNext(true)
}
const { isPlaying } = usePlayer()
isPlaying.value = false
}, 3000)
return return
} }