fix(playback): await all async methods in interna API

Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2306>
This commit is contained in:
wvffle 2022-12-27 13:18:56 +00:00 committed by petitminion
parent b04e087ca6
commit af6b5c3843
3 changed files with 10 additions and 11 deletions

View File

@ -96,11 +96,11 @@ export class HTMLSound implements Sound {
} }
async play () { async play () {
this.#audio.play() return this.#audio.play()
} }
async pause () { async pause () {
this.#audio.pause() return this.#audio.pause()
} }
async seekTo (seconds: number) { async seekTo (seconds: number) {

View File

@ -36,11 +36,10 @@ export const usePlayer = createGlobalState(() => {
if (!sound) return if (!sound) return
if (isPlaying.value) { if (isPlaying.value) {
sound.play() return sound.play()
return
} }
sound.pause() return sound.pause()
}) })
// Create first track when we initialize the page // Create first track when we initialize the page

View File

@ -183,15 +183,15 @@ export const useQueue = createGlobalState(() => {
// Play track // Play track
const playTrack = async (trackIndex: number, forceRestartIfCurrent = false) => { const playTrack = async (trackIndex: number, forceRestartIfCurrent = false) => {
if (isPlaying.value) currentSound.value?.pause() if (isPlaying.value) await currentSound.value?.pause()
if (currentIndex.value !== trackIndex) currentSound.value?.seekTo(0) if (currentIndex.value !== trackIndex) await currentSound.value?.seekTo(0)
const shouldRestart = forceRestartIfCurrent && currentIndex.value === trackIndex const shouldRestart = forceRestartIfCurrent && currentIndex.value === trackIndex
const nextTrackIsTheSame = queue.value[trackIndex]?.id === currentTrack.value?.id const nextTrackIsTheSame = queue.value[trackIndex]?.id === currentTrack.value?.id
if (shouldRestart || nextTrackIsTheSame) { if (shouldRestart || nextTrackIsTheSame) {
currentSound.value?.seekTo(0) await currentSound.value?.seekTo(0)
if (isPlaying.value) currentSound.value?.play() if (isPlaying.value) await currentSound.value?.play()
if (shouldRestart) return if (shouldRestart) return
} }
@ -303,8 +303,8 @@ export const useQueue = createGlobalState(() => {
// Clear // Clear
const clearRadio = ref(false) const clearRadio = ref(false)
const clear = async () => { const clear = async () => {
currentSound.value?.pause() await currentSound.value?.pause()
currentSound.value?.seekTo(0) await currentSound.value?.seekTo(0)
currentSound.value?.dispose() currentSound.value?.dispose()
clearRadio.value = true clearRadio.value = true