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:
parent
b04e087ca6
commit
af6b5c3843
|
@ -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) {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue