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
8d5b0f5d56
commit
037a61e731
@ -23,4 +23,8 @@ global.prevListPlayIndex = -1
|
||||
global.syncKeyInfo = {}
|
||||
global.isSyncEnableing = false
|
||||
|
||||
global.isPlaying = false
|
||||
global.playInfo = {
|
||||
isPlaying: false,
|
||||
currentPlayMusicInfo: null,
|
||||
duration: 0,
|
||||
}
|
||||
|
@ -110,29 +110,29 @@ export const playMusic = async(tracks, time) => {
|
||||
}
|
||||
}
|
||||
|
||||
let musicId = null
|
||||
let duration = 0
|
||||
let artwork = null
|
||||
// let musicId = null
|
||||
// let duration = 0
|
||||
// let artwork = null
|
||||
export const updateMetaInfo = async track => {
|
||||
// console.log('+++++updateMusicPic+++++', track.artwork, track.duration)
|
||||
|
||||
if (track.musicId == musicId) {
|
||||
if (track.artwork != null) artwork = track.artwork
|
||||
if (track.duration != null) duration = track.duration
|
||||
} else {
|
||||
musicId = track.musicId
|
||||
artwork = track.artwork
|
||||
duration = track.duration == null ? 0 : track.duration
|
||||
}
|
||||
// if (track.musicId == musicId) {
|
||||
// if (global.playInfo.musicInfo.img != null) artwork = global.playInfo.musicInfo.img
|
||||
// if (track.duration != null) duration = global.playInfo.duration
|
||||
// } else {
|
||||
// musicId = track.musicId
|
||||
// artwork = global.playInfo.musicInfo.img
|
||||
// duration = global.playInfo.duration || 0
|
||||
// }
|
||||
|
||||
global.isPlaying = await TrackPlayer.getState() == State.Playing
|
||||
global.playInfo.isPlaying = await TrackPlayer.getState() == State.Playing
|
||||
await TrackPlayer.updateNowPlayingMetadata({
|
||||
title: track.title || 'Unknow',
|
||||
artist: track.artist || 'Unknow',
|
||||
album: track.album || null,
|
||||
artwork,
|
||||
duration,
|
||||
}, global.isPlaying)
|
||||
artwork: global.playInfo?.currentPlayMusicInfo?.img || null,
|
||||
duration: global.playInfo?.duration || 0,
|
||||
}, global.playInfo.isPlaying)
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,7 +15,7 @@ let retryGetUrlId = null
|
||||
let retryGetUrlNum = 0
|
||||
let trackId = ''
|
||||
let errorTime = 0
|
||||
let prevDuration = 0
|
||||
// let prevDuration = 0
|
||||
const tempIdRxp = /\/\/default$|\/\/default\/\/restorePlay$/
|
||||
// let isPlaying = false
|
||||
|
||||
@ -155,21 +155,23 @@ export default async() => {
|
||||
}
|
||||
if (global.isPlayedExit) return handleExitApp()
|
||||
|
||||
// console.log('currentIsPlaying', currentIsPlaying, global.isPlaying)
|
||||
if (currentIsPlaying == global.isPlaying) {
|
||||
// console.log('currentIsPlaying', currentIsPlaying, global.playInfo.isPlaying)
|
||||
if (currentIsPlaying == global.playInfo.isPlaying) {
|
||||
const duration = await TrackPlayer.getDuration()
|
||||
// console.log('currentIsPlaying', prevDuration, duration)
|
||||
if (prevDuration != duration) {
|
||||
prevDuration = duration
|
||||
// console.log('currentIsPlaying', global.playInfo.duration, duration)
|
||||
if (global.playInfo.duration != duration) {
|
||||
global.playInfo.duration = duration
|
||||
const trackInfo = await getCurrentTrack()
|
||||
if (trackInfo) {
|
||||
delayUpdateMusicInfo(buildTrack({ musicInfo: { ...trackInfo.original }, type: trackInfo.type, url: trackInfo.url, duration }))
|
||||
if (trackInfo && global.playInfo.currentPlayMusicInfo) {
|
||||
delayUpdateMusicInfo(buildTrack({ musicInfo: global.playInfo.currentPlayMusicInfo, type: trackInfo.type, url: trackInfo.url, duration }))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const [duration, trackInfo] = await Promise.all([TrackPlayer.getDuration(), getCurrentTrack()])
|
||||
prevDuration = duration
|
||||
delayUpdateMusicInfo(buildTrack({ musicInfo: { ...trackInfo.original }, type: trackInfo.type, url: trackInfo.url, duration: prevDuration }))
|
||||
global.playInfo.duration = duration
|
||||
if (trackInfo && global.playInfo.currentPlayMusicInfo) {
|
||||
delayUpdateMusicInfo(buildTrack({ musicInfo: global.playInfo.currentPlayMusicInfo, type: trackInfo.type, url: trackInfo.url, duration }))
|
||||
}
|
||||
}
|
||||
})
|
||||
TrackPlayer.addEventListener(TPEvent.PlaybackTrackChanged, async info => {
|
||||
|
@ -114,11 +114,11 @@ const handlePlayMusic = async({ getState, dispatch, playMusicInfo, musicInfo, is
|
||||
}
|
||||
setLyric('')
|
||||
console.log('Handle Play Music ====================>', musicInfo.name)
|
||||
_playMusicInfo = musicInfo
|
||||
global.playInfo.currentPlayMusicInfo = _playMusicInfo = musicInfo
|
||||
let id = `${musicInfo.source}//${musicInfo.songmid}//${type}`
|
||||
playMusicId = id
|
||||
|
||||
global.isPlaying = false
|
||||
global.playInfo.isPlaying = false
|
||||
if (global.restorePlayInfo) {
|
||||
const track = buildTrack({ musicInfo, type })
|
||||
delayUpdateMusicInfo(track)
|
||||
|
@ -33,6 +33,7 @@ const mutations = {
|
||||
break
|
||||
}
|
||||
// console.log('+++++++targetMusic+++++++', targetMusic)
|
||||
datas.musicInfo.img = datas.url
|
||||
targetMusic.img = datas.url
|
||||
const newState = { ...state }
|
||||
if (state.playMusicInfo.musicInfo.source == datas.musicInfo.source && state.playMusicInfo.musicInfo.songmid === datas.musicInfo.songmid) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user