From 10c6799d120049dfd03b1d2def0958fa9cdaec94 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Tue, 14 Sep 2021 15:52:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=B6=E4=BB=96=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=92=AD=E6=94=BE=E5=A3=B0=E9=9F=B3=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=BD=AF=E4=BB=B6=E4=B8=B4=E6=97=B6=E6=9A=82=E5=81=9C=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E5=90=8E=E9=80=9A=E7=9F=A5=E6=A0=8F=E7=9A=84=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E4=BB=8D=E6=98=BE=E7=A4=BA=E6=AD=A3=E5=9C=A8=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 6 ++-- package.json | 2 +- publish/changeLog.md | 1 + src/plugins/player/service.js | 62 +++++++++++++++++++---------------- 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/package-lock.json b/package-lock.json index f775a5a..f9c8131 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 2b202f0..af5fbdf 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/publish/changeLog.md b/publish/changeLog.md index 580e31f..b584041 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -8,3 +8,4 @@ - 修复mg排行榜无法加载的问题 - 修复列表导出失败时的提示信息缺失翻译的问题 - 修复 Android 11 导入列表时,不显示备份文件的问题 +- 修复其他应用播放声音时,软件临时暂停播放后通知栏的状态仍显示正在播放的问题 diff --git a/src/plugins/player/service.js b/src/plugins/player/service.js index 3d2627b..7b736b0 100644 --- a/src/plugins/player/service.js +++ b/src/plugins/player/service.js @@ -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)