修复调整当前播放歌曲的位置时会导致切歌的问题

pull/733/head
lyswhut 2021-12-11 16:24:00 +08:00
parent 5aad81c696
commit 96c3034a07
2 changed files with 17 additions and 4 deletions

View File

@ -3,10 +3,16 @@ import { onBeforeUnmount } from '@renderer/utils/vueTools'
import { player as eventPlayerNames, list as eventListNames } from '@renderer/event/names' import { player as eventPlayerNames, list as eventListNames } from '@renderer/event/names'
import { playInfo, playMusicInfo, updatePlayIndex } from '@renderer/core/share/player' import { playInfo, playMusicInfo, updatePlayIndex } from '@renderer/core/share/player'
import { getList } from '@renderer/core/share/utils' import { getList } from '@renderer/core/share/utils'
import { throttle } from '@renderer/utils'
const changedListIds = new Set()
export default ({ playNext }) => { export default ({ playNext }) => {
const handleListChange = listIds => { const throttleListChange = throttle(() => {
if (!listIds.includes(playInfo.playListId) && !listIds.includes(playMusicInfo.listId)) return const isSkip = !changedListIds.has(playInfo.playListId) && !changedListIds.has(playMusicInfo.listId)
changedListIds.clear()
if (isSkip) return
const { playIndex } = updatePlayIndex() const { playIndex } = updatePlayIndex()
if (playIndex < 0 && !playMusicInfo.isTempPlay) { // 歌曲被移除 if (playIndex < 0 && !playMusicInfo.isTempPlay) { // 歌曲被移除
if (getList(playMusicInfo.listId).length) { if (getList(playMusicInfo.listId).length) {
@ -15,6 +21,13 @@ export default ({ playNext }) => {
window.eventHub.emit(eventPlayerNames.setStop) window.eventHub.emit(eventPlayerNames.setStop)
} }
} }
})
const handleListChange = listIds => {
for (const id of listIds) {
changedListIds.add(id)
}
throttleListChange()
} }
window.eventHub.on(eventListNames.listChange, handleListChange) window.eventHub.on(eventListNames.listChange, handleListChange)

View File

@ -402,8 +402,8 @@ export const getPlayList = () => rendererInvoke(NAMES.mainWindow.get_playlist).c
let filePath = path.join(dataPath, 'playList.json.bak') let filePath = path.join(dataPath, 'playList.json.bak')
rendererInvoke(NAMES.mainWindow.show_dialog, { rendererInvoke(NAMES.mainWindow.show_dialog, {
type: 'error', type: 'error',
message: window.i18n.t('store.state.load_list_file_error_title'), message: window.i18n.t('load_list_file_error_title'),
detail: window.i18n.t('store.state.load_list_file_error_detail', { detail: window.i18n.t('load_list_file_error_detail', {
path: filePath, path: filePath,
detail: error.message, detail: error.message,
}), }),