修复删除列表中正在播放的歌曲时不会自动切歌的问题

pull/590/head
lyswhut 2021-08-01 20:07:40 +08:00
parent d44c2c26a8
commit 7e3ee38920
1 changed files with 39 additions and 15 deletions

View File

@ -141,6 +141,7 @@ const getLyric = function(musicInfo, retryedSource = [], originMusic) {
}) })
} }
let prevPlayIndex
// getters // getters
const getters = { const getters = {
list: state => state.listInfo.list, list: state => state.listInfo.list,
@ -163,15 +164,16 @@ const getters = {
if (list) playIndex = list.list.findIndex(m => m.songmid == state.playMusicInfo.musicInfo.songmid) if (list) playIndex = list.list.findIndex(m => m.songmid == state.playMusicInfo.musicInfo.songmid)
} }
} }
// console.log({ if (listPlayIndex > -1) prevPlayIndex = listPlayIndex
// listId, console.log({
// playIndex, listId,
// playListId, playIndex,
// listPlayIndex, playListId,
// isPlayList, listPlayIndex,
// isTempPlay, isPlayList,
// musicInfo: state.playMusicInfo.musicInfo, isTempPlay,
// }) // musicInfo: state.playMusicInfo.musicInfo,
})
return { return {
listId, listId,
playIndex, playIndex,
@ -250,9 +252,9 @@ const actions = {
if (state.playedList.length) { if (state.playedList.length) {
// 从已播放列表移除播放列表已删除的歌曲 // 从已播放列表移除播放列表已删除的歌曲
let index 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] 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) commit('removePlayedList', index)
continue continue
} }
@ -273,7 +275,18 @@ const actions = {
}) })
if (!filteredList.length) return commit('setPlayMusicInfo', null) if (!filteredList.length) return commit('setPlayMusicInfo', null)
const playInfo = getters.playInfo 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) let currentIndex = filteredList.findIndex(m => m.songmid == currentMusic.songmid)
if (currentIndex == -1) currentIndex = 0 if (currentIndex == -1) currentIndex = 0
let nextIndex = currentIndex let nextIndex = currentIndex
@ -312,9 +325,9 @@ const actions = {
if (state.playedList.length) { if (state.playedList.length) {
// 从已播放列表移除播放列表已删除的歌曲 // 从已播放列表移除播放列表已删除的歌曲
let index 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] 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) commit('removePlayedList', index)
continue continue
} }
@ -335,7 +348,18 @@ const actions = {
if (!filteredList.length) return commit('setPlayMusicInfo', null) if (!filteredList.length) return commit('setPlayMusicInfo', null)
const playInfo = getters.playInfo 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 currentIndex = filteredList.findIndex(m => m.songmid == currentMusic.songmid)
let nextIndex = currentIndex let nextIndex = currentIndex
switch (rootState.setting.player.togglePlayMethod) { switch (rootState.setting.player.togglePlayMethod) {