fix: ensure preloaded track exists
Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2346>
This commit is contained in:
parent
186c8000f8
commit
a65d3722c9
|
@ -69,6 +69,8 @@ export class HTMLSound implements Sound {
|
|||
this.#audio.src = source
|
||||
this.#audio.preload = 'auto'
|
||||
|
||||
console.log('CREATED SOUND INSTANCE', this)
|
||||
|
||||
useEventListener(this.#audio, 'ended', () => this.#soundEndEventHook.trigger(this))
|
||||
useEventListener(this.#audio, 'timeupdate', () => {
|
||||
if (this.#audio.currentTime === 0) {
|
||||
|
|
|
@ -122,9 +122,8 @@ export const useTracks = createGlobalState(() => {
|
|||
}, 3000, { immediate: false })
|
||||
|
||||
// Preload next track
|
||||
const { start: startPreloadTimeout, stop: abortPreload } = useTimeoutFn(async (index) => {
|
||||
const { queue } = useQueue()
|
||||
const sound = await createSound(queue.value[index as number])
|
||||
const { start: preload, stop: abortPreload } = useTimeoutFn(async (track: QueueTrack) => {
|
||||
const sound = await createSound(track)
|
||||
await sound.preload()
|
||||
}, 100, { immediate: false })
|
||||
|
||||
|
@ -172,12 +171,12 @@ export const useTracks = createGlobalState(() => {
|
|||
if (!hasNext.value) return
|
||||
|
||||
const nextTrack = queue.value[currentIndex.value + 1]
|
||||
if (nextTrack && lastTrack === nextTrack) return
|
||||
if (!nextTrack || lastTrack === nextTrack) return
|
||||
lastTrack = nextTrack
|
||||
|
||||
// NOTE: Preload next track
|
||||
// @ts-expect-error vueuse is wrongly typed: https://github.com/vueuse/vueuse/issues/2691
|
||||
startPreloadTimeout(currentIndex.value + 1)
|
||||
preload(nextTrack)
|
||||
})
|
||||
|
||||
syncRef(track, currentTrack, {
|
||||
|
|
Loading…
Reference in New Issue