From 7e3ee389202239190c3254611520f5d86cba0c4a Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sun, 1 Aug 2021 20:07:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=A0=E9=99=A4=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E4=B8=AD=E6=AD=A3=E5=9C=A8=E6=92=AD=E6=94=BE=E7=9A=84?= =?UTF-8?q?=E6=AD=8C=E6=9B=B2=E6=97=B6=E4=B8=8D=E4=BC=9A=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=88=87=E6=AD=8C=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/store/modules/player.js | 54 ++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/src/renderer/store/modules/player.js b/src/renderer/store/modules/player.js index 75a7bc9f..f96bafeb 100644 --- a/src/renderer/store/modules/player.js +++ b/src/renderer/store/modules/player.js @@ -141,6 +141,7 @@ const getLyric = function(musicInfo, retryedSource = [], originMusic) { }) } +let prevPlayIndex // getters const getters = { list: state => state.listInfo.list, @@ -163,15 +164,16 @@ const getters = { if (list) playIndex = list.list.findIndex(m => m.songmid == state.playMusicInfo.musicInfo.songmid) } } - // console.log({ - // listId, - // playIndex, - // playListId, - // listPlayIndex, - // isPlayList, - // isTempPlay, - // musicInfo: state.playMusicInfo.musicInfo, - // }) + if (listPlayIndex > -1) prevPlayIndex = listPlayIndex + console.log({ + listId, + playIndex, + playListId, + listPlayIndex, + isPlayList, + isTempPlay, + // musicInfo: state.playMusicInfo.musicInfo, + }) return { listId, playIndex, @@ -250,9 +252,9 @@ const actions = { if (state.playedList.length) { // 从已播放列表移除播放列表已删除的歌曲 let index - for (index = state.playedList.indexOf(state.playMusicInfo) - 1; index > -1; index--) { + for (index = state.playedList.findIndex(m => m.songmid === state.playMusicInfo.musicInfo.songmid) - 1; index > -1; index--) { const playMusicInfo = state.playedList[index] - if (playMusicInfo.listId == currentListId && !currentList.includes(playMusicInfo.musicInfo)) { + if (playMusicInfo.listId == currentListId && !currentList.some(m => m.songmid === playMusicInfo.musicInfo.songmid)) { commit('removePlayedList', index) continue } @@ -273,7 +275,18 @@ const actions = { }) if (!filteredList.length) return commit('setPlayMusicInfo', null) const playInfo = getters.playInfo - const currentMusic = currentList[playInfo.listPlayIndex] + let currentMusic + if (playInfo.listPlayIndex < 0) { + let index = prevPlayIndex + if (index > currentList.length - 1) index = 0 + while (index > -1) { + currentMusic = currentList[index] + if (currentMusic) break + index-- + } + } else { + currentMusic = currentList[playInfo.listPlayIndex] + } let currentIndex = filteredList.findIndex(m => m.songmid == currentMusic.songmid) if (currentIndex == -1) currentIndex = 0 let nextIndex = currentIndex @@ -312,9 +325,9 @@ const actions = { if (state.playedList.length) { // 从已播放列表移除播放列表已删除的歌曲 let index - for (index = state.playedList.indexOf(state.playMusicInfo) + 1; index < state.playedList.length; index++) { + for (index = state.playedList.findIndex(m => m.songmid === state.playMusicInfo.musicInfo.songmid) + 1; index < state.playedList.length; index++) { const playMusicInfo = state.playedList[index] - if (playMusicInfo.listId == currentListId && !currentList.includes(playMusicInfo.musicInfo)) { + if (playMusicInfo.listId == currentListId && !currentList.some(m => m.songmid === playMusicInfo.musicInfo.songmid)) { commit('removePlayedList', index) continue } @@ -335,7 +348,18 @@ const actions = { if (!filteredList.length) return commit('setPlayMusicInfo', null) const playInfo = getters.playInfo - const currentMusic = currentList[playInfo.listPlayIndex] + let currentMusic + if (playInfo.listPlayIndex < 0) { + let index = prevPlayIndex - 1 + if (index < 0) index = currentList.length - 1 + while (index > -1) { + currentMusic = currentList[index] + if (currentMusic) break + index-- + } + } else { + currentMusic = currentList[playInfo.listPlayIndex] + } let currentIndex = filteredList.findIndex(m => m.songmid == currentMusic.songmid) let nextIndex = currentIndex switch (rootState.setting.player.togglePlayMethod) {