优化调用播放模块逻辑

This commit is contained in:
lyswhut 2023-04-01 13:29:28 +08:00
parent 8677d6a38b
commit cc2f95b3e7
3 changed files with 16 additions and 5 deletions

View File

@ -14,6 +14,7 @@ import { saveData } from '@/plugins/storage'
import { throttle } from '@/utils/common'
import { saveFontSize, saveViewPrevState } from '@/utils/data'
import { showPactModal as handleShowPactModal } from '@/navigation'
import { hideLyric } from '@/utils/nativeModules/lyricDesktop'
const throttleSaveSetting = throttle(() => {
@ -54,6 +55,7 @@ export const exitApp = () => {
Promise.all([
hideDesktopLyric(),
destroyPlayer(),
hideLyric(),
]).finally(() => {
isDestroying = false
utilExitApp()

View File

@ -126,8 +126,8 @@ export const updateMetaData = async(musicInfo: LX.Player.MusicInfo, isPlay: bool
}
}
export const playMusic = async(musicInfo: LX.Player.PlayMusic, url: string, time: number) => {
// console.log(tracks, time)
const handlePlayMusic = async(musicInfo: LX.Player.PlayMusic, url: string, time: number) => {
// console.log(tracks, time)
const tracks = buildTracks(musicInfo, url)
const track = tracks[0]
// await updateMusicInfo(track)
@ -162,6 +162,15 @@ export const playMusic = async(musicInfo: LX.Player.PlayMusic, url: string, time
void TrackPlayer.remove(Array(queue.length - 2).fill(null).map((_, i) => i)).then(() => list.splice(0, list.length - 2))
}
}
let playPromise = Promise.resolve()
let actionId = Math.random()
export const playMusic = (musicInfo: LX.Player.PlayMusic, url: string, time: number) => {
const id = actionId = Math.random()
playPromise.finally(() => {
if (id != actionId) return
playPromise = handlePlayMusic(musicInfo, url, time)
})
}
// let musicId = null
// let duration = 0

View File

@ -145,7 +145,7 @@ const playMusic = ((fn: (musicInfo: LX.Player.PlayMusic, url: string, time: numb
}
}
})((musicInfo, url, time) => {
void handlePlayMusic(musicInfo, url, time)
handlePlayMusic(musicInfo, url, time)
})
export const setResource = (musicInfo: LX.Player.PlayMusic, url: string, duration?: number) => {