From ee623f74bbbe848e09b3c092cc3b07109c12b7ba Mon Sep 17 00:00:00 2001 From: lyswhut Date: Thu, 16 Jun 2022 11:18:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=81=9C=E6=AD=A2=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E5=90=8E=E7=9A=84=E6=92=AD=E6=94=BE=E5=99=A8=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=B8=85=E7=90=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/toside/music/mobile/lyric/Lyric.java | 14 ++++++++------ publish/changeLog.md | 1 + src/plugins/lyric.js | 2 +- src/plugins/player/playList.js | 4 ++-- src/store/modules/player/action.js | 13 +++++++++---- src/store/modules/player/reducer.js | 4 ++-- src/utils/lyric.js | 7 +++++++ 7 files changed, 30 insertions(+), 15 deletions(-) diff --git a/android/app/src/main/java/cn/toside/music/mobile/lyric/Lyric.java b/android/app/src/main/java/cn/toside/music/mobile/lyric/Lyric.java index 85bb6c9..e87bac4 100644 --- a/android/app/src/main/java/cn/toside/music/mobile/lyric/Lyric.java +++ b/android/app/src/main/java/cn/toside/music/mobile/lyric/Lyric.java @@ -87,13 +87,14 @@ public class Lyric extends LyricPlayer { private void setViewLyric(int lineNum) { lastLine = lineNum; if (lyricView == null) return; - if (lineNum < 0 || lineNum > lines.size() - 1) return; - HashMap line = (HashMap) lines.get(lineNum); - if (line == null) { - lyricView.setLyric("", new ArrayList<>(0)); - } else { - lyricView.setLyric((String) line.get("text"), (ArrayList) line.get("extendedLyrics")); + if (lineNum >= 0 && lineNum < lines.size()) { + HashMap line = (HashMap) lines.get(lineNum); + if (line != null) { + lyricView.setLyric((String) line.get("text"), (ArrayList) line.get("extendedLyrics")); + return; + } } + lyricView.setLyric("", new ArrayList<>(0)); } public void showLyric(Bundle options, Promise promise) { @@ -136,6 +137,7 @@ public class Lyric extends LyricPlayer { @Override public void onSetLyric(List lines) { this.lines = lines; + setViewLyric(-1); // for (int i = 0; i < lines.size(); i++) { // HashMap line = (HashMap) lines.get(i); // Log.d("Lyric", "onSetLyric: " +(String) line.get("text") + " " + line.get("extendedLyrics")); diff --git a/publish/changeLog.md b/publish/changeLog.md index 14d6c4c..741e77e 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -15,3 +15,4 @@ - 修复桌面歌词转繁体设置不立即生效的问题 - 修复搜索、歌单、排行榜列表可能在切换新内容后出现上次列表内容的残留问题(#118) - 修复在某些系统上播放音乐会导致应用崩溃的问题(#129) +- 修复停止播放后的播放器状态清理问题 diff --git a/src/plugins/lyric.js b/src/plugins/lyric.js index caf733f..89a4c9c 100644 --- a/src/plugins/lyric.js +++ b/src/plugins/lyric.js @@ -32,8 +32,8 @@ const lrcTools = { }, onSetLyric(lines) { this.currentLines = lines - for (const hook of this.setLyricHooks) hook(lines) for (const hook of this.playHooks) hook(-1, '') + for (const hook of this.setLyricHooks) hook(lines) }, addPlayHook(callback) { this.playHooks.push(callback) diff --git a/src/plugins/player/playList.js b/src/plugins/player/playList.js index 81f7dfc..b594e3d 100644 --- a/src/plugins/player/playList.js +++ b/src/plugins/player/playList.js @@ -135,7 +135,7 @@ export const updateMetaInfo = async track => { // artwork = global.playInfo.musicInfo.img // duration = global.playInfo.duration || 0 // } - + console.log(global.playInfo) global.playInfo.isPlaying = await TrackPlayer.getState() == State.Playing await TrackPlayer.updateNowPlayingMetadata({ title: track.title || 'Unknow', @@ -143,7 +143,7 @@ export const updateMetaInfo = async track => { album: track.album || null, artwork: isShowNotificationImage ? global.playInfo?.currentPlayMusicInfo?.img ?? null : null, duration: global.playInfo?.duration || 0, - }, global.playInfo.isPlaying) + }, global.playInfo?.isPlaying) } diff --git a/src/store/modules/player/action.js b/src/store/modules/player/action.js index 4a75023..4ed2663 100644 --- a/src/store/modules/player/action.js +++ b/src/store/modules/player/action.js @@ -20,7 +20,7 @@ import { import { getRandom } from '@/utils' import { getMusicUrl, saveMusicUrl, getLyric, saveLyric, assertApiSupport, savePlayInfo, saveList, checkNotificationPermission } from '@/utils/tools' import { playInfo as playInfoGetter } from './getter' -import { play as lrcPlay, setLyric, pause as lrcPause, toggleTranslation as lrcToggleTranslation, toggleRoma as lrcToggleRoma } from '@/utils/lyric' +import { play as lrcPlay, setLyric, pause as lrcPause, stop as lrcStop, toggleTranslation as lrcToggleTranslation, toggleRoma as lrcToggleRoma } from '@/utils/lyric' import { showLyric, hideLyric, setLyric as lrcdSetLyric, @@ -127,7 +127,7 @@ const handlePlayMusic = async({ getState, dispatch, playMusicInfo, musicInfo, is clearTimeout(timeout) timeout = null } - setLyric('') + // setLyric('') console.log('Handle Play Music ====================>', musicInfo.name) global.playInfo.currentPlayMusicInfo = _playMusicInfo = musicInfo let id = `${musicInfo.source}//${musicInfo.songmid}//${type}` @@ -304,9 +304,11 @@ const getNextMusicInfo = state => { */ export const stopMusic = () => async(dispatch, getState) => { _playMusicInfo = null - dispatch(setPlayIndex(-1)) + await dispatch(playMusic(null)) dispatch(setStatus({ status: STATUS.stop, text: '' })) - await stop() + lrcStop() + savePlayInfo(null) + delayUpdateMusicInfo({}) } export const pauseMusic = () => async(dispatch, getState) => { @@ -481,6 +483,9 @@ export const playMusic = playMusicInfo => async(dispatch, getState) => { playIndex, }, }) + global.playInfo.currentPlayMusicInfo = _playMusicInfo = playMusicInfo + playMusicId = '' + global.playInfo.isPlaying = false await stop() } else { // 设置歌曲信息并播放歌曲 setLyric('') diff --git a/src/store/modules/player/reducer.js b/src/store/modules/player/reducer.js index decdcf4..db16282 100644 --- a/src/store/modules/player/reducer.js +++ b/src/store/modules/player/reducer.js @@ -119,8 +119,8 @@ const mutations = { [TYPES.setPlayMusicInfo](state, { playMusicInfo, playIndex }) { return { ...state, - playMusicInfo: playMusicInfo, - playIndex: playIndex, + playMusicInfo, + playIndex, } }, } diff --git a/src/utils/lyric.js b/src/utils/lyric.js index ecaac64..aadbed7 100644 --- a/src/utils/lyric.js +++ b/src/utils/lyric.js @@ -49,6 +49,13 @@ export const pause = () => { lrcdPause() } +/** + * stop lyric + */ +export const stop = () => { + setLyric('') +} + /** * toggle show translation * @param {Boolean} isShowTranslation is show translation