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 { throttle } from '@/utils/common'
|
||||||
import { saveFontSize, saveViewPrevState } from '@/utils/data'
|
import { saveFontSize, saveViewPrevState } from '@/utils/data'
|
||||||
import { showPactModal as handleShowPactModal } from '@/navigation'
|
import { showPactModal as handleShowPactModal } from '@/navigation'
|
||||||
|
import { hideLyric } from '@/utils/nativeModules/lyricDesktop'
|
||||||
|
|
||||||
|
|
||||||
const throttleSaveSetting = throttle(() => {
|
const throttleSaveSetting = throttle(() => {
|
||||||
@ -54,6 +55,7 @@ export const exitApp = () => {
|
|||||||
Promise.all([
|
Promise.all([
|
||||||
hideDesktopLyric(),
|
hideDesktopLyric(),
|
||||||
destroyPlayer(),
|
destroyPlayer(),
|
||||||
|
hideLyric(),
|
||||||
]).finally(() => {
|
]).finally(() => {
|
||||||
isDestroying = false
|
isDestroying = false
|
||||||
utilExitApp()
|
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) => {
|
const handlePlayMusic = async(musicInfo: LX.Player.PlayMusic, url: string, time: number) => {
|
||||||
// console.log(tracks, time)
|
// console.log(tracks, time)
|
||||||
const tracks = buildTracks(musicInfo, url)
|
const tracks = buildTracks(musicInfo, url)
|
||||||
const track = tracks[0]
|
const track = tracks[0]
|
||||||
// await updateMusicInfo(track)
|
// await updateMusicInfo(track)
|
||||||
@ -144,8 +144,8 @@ export const playMusic = async(musicInfo: LX.Player.PlayMusic, url: string, time
|
|||||||
// let startupAutoPlay = settingState.setting['player.startupAutoPlay']
|
// let startupAutoPlay = settingState.setting['player.startupAutoPlay']
|
||||||
global.lx.restorePlayInfo = null
|
global.lx.restorePlayInfo = null
|
||||||
|
|
||||||
// TODO startupAutoPlay
|
// TODO startupAutoPlay
|
||||||
// if (startupAutoPlay) store.dispatch(playerAction.playMusic())
|
// if (startupAutoPlay) store.dispatch(playerAction.playMusic())
|
||||||
} else {
|
} else {
|
||||||
await TrackPlayer.play()
|
await TrackPlayer.play()
|
||||||
}
|
}
|
||||||
@ -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))
|
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 musicId = null
|
||||||
// let duration = 0
|
// let duration = 0
|
||||||
|
@ -145,7 +145,7 @@ const playMusic = ((fn: (musicInfo: LX.Player.PlayMusic, url: string, time: numb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})((musicInfo, url, time) => {
|
})((musicInfo, url, time) => {
|
||||||
void handlePlayMusic(musicInfo, url, time)
|
handlePlayMusic(musicInfo, url, time)
|
||||||
})
|
})
|
||||||
|
|
||||||
export const setResource = (musicInfo: LX.Player.PlayMusic, url: string, duration?: number) => {
|
export const setResource = (musicInfo: LX.Player.PlayMusic, url: string, duration?: number) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user