mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-05-23 22:37:41 +08:00
优化调用播放模块逻辑
This commit is contained in:
parent
8677d6a38b
commit
cc2f95b3e7
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user