修复其他应用播放声音时,软件临时暂停播放后通知栏的状态仍显示正在播放的问题

This commit is contained in:
lyswhut 2021-09-14 15:52:19 +08:00
parent d343b06130
commit 10c6799d12
4 changed files with 38 additions and 33 deletions

6
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "lx-music-mobile",
"version": "0.8.1-beta3",
"version": "0.8.1-beta4",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -9784,8 +9784,8 @@
"integrity": "sha512-Ls9qiNZzW/OLFoI25wfjjAcrf2DZ975hn2vr6U9gyuxi2nooVbzQeFoQS5vQcbCt9QX5NY8ASEEAtlLdIa6KVg=="
},
"react-native-track-player": {
"version": "git+https://github.com/lyswhut/react-native-track-player.git#48e273d0222f5bfa4306a3dc8485914787cc4a12",
"from": "git+https://github.com/lyswhut/react-native-track-player.git#48e273d0222f5bfa4306a3dc8485914787cc4a12"
"version": "git+https://github.com/lyswhut/react-native-track-player.git#248576352b5d0188a52831abf2bddab6cdef3af0",
"from": "git+https://github.com/lyswhut/react-native-track-player.git#248576352b5d0188a52831abf2bddab6cdef3af0"
},
"react-native-vector-icons": {
"version": "8.1.0",

View File

@ -62,7 +62,7 @@
"react-native-pager-view": "^5.4.1",
"react-native-randombytes": "^3.6.1",
"react-native-splash-screen": "^3.2.0",
"react-native-track-player": "git+https://github.com/lyswhut/react-native-track-player.git#48e273d0222f5bfa4306a3dc8485914787cc4a12",
"react-native-track-player": "git+https://github.com/lyswhut/react-native-track-player.git#248576352b5d0188a52831abf2bddab6cdef3af0",
"react-native-vector-icons": "^8.1.0",
"react-redux": "^7.2.5",
"readable-stream": "1.0.33",

View File

@ -8,3 +8,4 @@
- 修复mg排行榜无法加载的问题
- 修复列表导出失败时的提示信息缺失翻译的问题
- 修复 Android 11 导入列表时,不显示备份文件的问题
- 修复其他应用播放声音时,软件临时暂停播放后通知栏的状态仍显示正在播放的问题

View File

@ -25,6 +25,26 @@ const handleExitApp = async() => {
exitApp()
}
const updateMetaData = async isPlaying => {
if (isPlaying == global.playInfo.isPlaying) {
const duration = await TrackPlayer.getDuration()
// console.log('currentIsPlaying', global.playInfo.duration, duration)
if (global.playInfo.duration != duration) {
global.playInfo.duration = duration
const trackInfo = await getCurrentTrack()
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()])
global.playInfo.duration = duration
if (trackInfo && global.playInfo.currentPlayMusicInfo) {
delayUpdateMusicInfo(buildTrack({ musicInfo: global.playInfo.currentPlayMusicInfo, type: trackInfo.type, url: trackInfo.url, duration }))
}
}
}
export default async() => {
if (isInitialized) return
@ -58,18 +78,18 @@ export default async() => {
handleExitApp()
})
TrackPlayer.addEventListener(TPEvent.RemoteDuck, async({ permanent, paused, ducking }) => {
console.log('remote-duck')
if (paused) {
store.dispatch(playerAction.setStatus({ status: STATUS.pause, text: '已暂停' }))
lrcPause()
} else {
store.dispatch(playerAction.setStatus({ status: STATUS.playing, text: '播放中...' }))
TrackPlayer.getPosition().then(position => {
lrcPlay(position * 1000)
})
}
})
// TrackPlayer.addEventListener(TPEvent.RemoteDuck, async({ permanent, paused, ducking }) => {
// console.log('remote-duck')
// if (paused) {
// store.dispatch(playerAction.setStatus({ status: STATUS.pause, text: '已暂停' }))
// lrcPause()
// } else {
// store.dispatch(playerAction.setStatus({ status: STATUS.playing, text: '播放中...' }))
// TrackPlayer.getPosition().then(position => {
// lrcPlay(position * 1000)
// })
// }
// })
TrackPlayer.addEventListener(TPEvent.PlaybackError, async err => {
console.log('playback-error', err)
@ -156,23 +176,7 @@ export default async() => {
if (global.isPlayedExit) return handleExitApp()
// console.log('currentIsPlaying', currentIsPlaying, global.playInfo.isPlaying)
if (currentIsPlaying == global.playInfo.isPlaying) {
const duration = await TrackPlayer.getDuration()
// console.log('currentIsPlaying', global.playInfo.duration, duration)
if (global.playInfo.duration != duration) {
global.playInfo.duration = duration
const trackInfo = await getCurrentTrack()
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()])
global.playInfo.duration = duration
if (trackInfo && global.playInfo.currentPlayMusicInfo) {
delayUpdateMusicInfo(buildTrack({ musicInfo: global.playInfo.currentPlayMusicInfo, type: trackInfo.type, url: trackInfo.url, duration }))
}
}
await updateMetaData(currentIsPlaying)
})
TrackPlayer.addEventListener(TPEvent.PlaybackTrackChanged, async info => {
// console.log('nextTrack====>', info)