修复停止播放后的播放器状态清理问题

This commit is contained in:
lyswhut 2022-06-16 11:18:56 +08:00
parent 02a8d8422f
commit ee623f74bb
7 changed files with 30 additions and 15 deletions

View File

@ -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<String>) 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<String>) 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"));

View File

@ -15,3 +15,4 @@
- 修复桌面歌词转繁体设置不立即生效的问题
- 修复搜索、歌单、排行榜列表可能在切换新内容后出现上次列表内容的残留问题(#118
- 修复在某些系统上播放音乐会导致应用崩溃的问题(#129
- 修复停止播放后的播放器状态清理问题

View File

@ -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)

View File

@ -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)
}

View File

@ -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('')

View File

@ -119,8 +119,8 @@ const mutations = {
[TYPES.setPlayMusicInfo](state, { playMusicInfo, playIndex }) {
return {
...state,
playMusicInfo: playMusicInfo,
playIndex: playIndex,
playMusicInfo,
playIndex,
}
},
}

View File

@ -49,6 +49,13 @@ export const pause = () => {
lrcdPause()
}
/**
* stop lyric
*/
export const stop = () => {
setLyric('')
}
/**
* toggle show translation
* @param {Boolean} isShowTranslation is show translation