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