fix: ensure preloaded track exists

Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2346>
environments/review-docs-fix-d-jlladr/deployments/17321
Kasper Seweryn 2023-01-29 12:10:02 +01:00 zatwierdzone przez Georg krause
rodzic 186c8000f8
commit a65d3722c9
2 zmienionych plików z 6 dodań i 5 usunięć

Wyświetl plik

@ -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) {

Wyświetl plik

@ -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, {