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 () {
this.#audio.play()
return this.#audio.play()
}
async pause () {
this.#audio.pause()
return this.#audio.pause()
}
async seekTo (seconds: number) {

View File

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

View File

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