From af6b5c3843b389519a49d0dfbd2ff2f158369cce Mon Sep 17 00:00:00 2001 From: wvffle Date: Tue, 27 Dec 2022 13:18:56 +0000 Subject: [PATCH] fix(playback): await all async methods in interna API Part-of: --- front/src/api/player.ts | 4 ++-- front/src/composables/audio/player.ts | 5 ++--- front/src/composables/audio/queue.ts | 12 ++++++------ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/front/src/api/player.ts b/front/src/api/player.ts index 2ff874062..e5108254c 100644 --- a/front/src/api/player.ts +++ b/front/src/api/player.ts @@ -96,11 +96,11 @@ export class HTMLSound implements Sound { } async play () { - this.#audio.play() + return this.#audio.play() } async pause () { - this.#audio.pause() + return this.#audio.pause() } async seekTo (seconds: number) { diff --git a/front/src/composables/audio/player.ts b/front/src/composables/audio/player.ts index 3555e9e00..e69dc5d56 100644 --- a/front/src/composables/audio/player.ts +++ b/front/src/composables/audio/player.ts @@ -36,11 +36,10 @@ export const usePlayer = createGlobalState(() => { if (!sound) return if (isPlaying.value) { - sound.play() - return + return sound.play() } - sound.pause() + return sound.pause() }) // Create first track when we initialize the page diff --git a/front/src/composables/audio/queue.ts b/front/src/composables/audio/queue.ts index 49bad7cc7..4caf8d1d8 100644 --- a/front/src/composables/audio/queue.ts +++ b/front/src/composables/audio/queue.ts @@ -183,15 +183,15 @@ export const useQueue = createGlobalState(() => { // Play track const playTrack = async (trackIndex: number, forceRestartIfCurrent = false) => { - if (isPlaying.value) currentSound.value?.pause() - if (currentIndex.value !== trackIndex) currentSound.value?.seekTo(0) + if (isPlaying.value) await currentSound.value?.pause() + if (currentIndex.value !== trackIndex) await currentSound.value?.seekTo(0) const shouldRestart = forceRestartIfCurrent && currentIndex.value === trackIndex const nextTrackIsTheSame = queue.value[trackIndex]?.id === currentTrack.value?.id if (shouldRestart || nextTrackIsTheSame) { - currentSound.value?.seekTo(0) - if (isPlaying.value) currentSound.value?.play() + await currentSound.value?.seekTo(0) + if (isPlaying.value) await currentSound.value?.play() if (shouldRestart) return } @@ -303,8 +303,8 @@ export const useQueue = createGlobalState(() => { // Clear const clearRadio = ref(false) const clear = async () => { - currentSound.value?.pause() - currentSound.value?.seekTo(0) + await currentSound.value?.pause() + await currentSound.value?.seekTo(0) currentSound.value?.dispose() clearRadio.value = true