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