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

This commit is contained in:
lyswhut
2021-12-11 16:24:00 +08:00
parent 5aad81c696
commit 96c3034a07
2 changed files with 17 additions and 4 deletions
@@ -3,10 +3,16 @@ import { onBeforeUnmount } from '@renderer/utils/vueTools'
import { player as eventPlayerNames, list as eventListNames } from '@renderer/event/names'
import { playInfo, playMusicInfo, updatePlayIndex } from '@renderer/core/share/player'
import { getList } from '@renderer/core/share/utils'
import { throttle } from '@renderer/utils'
const changedListIds = new Set()
export default ({ playNext }) => {
const handleListChange = listIds => {
if (!listIds.includes(playInfo.playListId) && !listIds.includes(playMusicInfo.listId)) return
const throttleListChange = throttle(() => {
const isSkip = !changedListIds.has(playInfo.playListId) && !changedListIds.has(playMusicInfo.listId)
changedListIds.clear()
if (isSkip) return
const { playIndex } = updatePlayIndex()
if (playIndex < 0 && !playMusicInfo.isTempPlay) { // 歌曲被移除
if (getList(playMusicInfo.listId).length) {
@@ -15,6 +21,13 @@ export default ({ playNext }) => {
window.eventHub.emit(eventPlayerNames.setStop)
}
}
})
const handleListChange = listIds => {
for (const id of listIds) {
changedListIds.add(id)
}
throttleListChange()
}
window.eventHub.on(eventListNames.listChange, handleListChange)