From 1f85492690b81771772f409ee5a13c78e44e0615 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Wed, 11 Aug 2021 09:59:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=92=AD=E6=94=BE=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=88=97=E8=A1=A8=E7=9A=84=E6=AD=8C=E6=9B=B2=E6=97=B6?= =?UTF-8?q?=E5=88=87=E6=AD=8C=E3=80=81=E6=AD=8C=E8=AF=8D=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 3 +- src/renderer/components/core/Player.vue | 8 +- src/renderer/store/modules/download.js | 6 +- src/renderer/store/modules/player.js | 99 +++++++++++++++---------- src/renderer/views/Download.vue | 18 ++--- 5 files changed, 78 insertions(+), 56 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index 585fe1c3..f7a35d89 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1,3 +1,4 @@ ### 修复 -- 修复随机播放下无法切歌的问题 +- 修复播放下载列表的歌曲时切歌的问题 +- 修复播放下载列表的歌曲时歌词无法显示的问题 diff --git a/src/renderer/components/core/Player.vue b/src/renderer/components/core/Player.vue index 678a2888..2f4c3d75 100644 --- a/src/renderer/components/core/Player.vue +++ b/src/renderer/components/core/Player.vue @@ -268,7 +268,7 @@ export default { 'setting.player.togglePlayMethod'(n) { audio.loop = n === 'singleLoop' if (this.playedList.length) this.clearPlayedList() - if (n == 'random') this.setPlayedList(this.playMusicInfo) + if (n == 'random' && !this.playMusicInfo.isTempPlay) this.setPlayedList(this.playMusicInfo) }, 'setting.player.isMute'(n) { audio.muted = n @@ -487,7 +487,7 @@ export default { const targetSong = this.targetSong - if (this.setting.player.togglePlayMethod == 'random') this.setPlayedList(this.playMusicInfo) + if (this.setting.player.togglePlayMethod == 'random' && !this.playMusicInfo.isTempPlay) this.setPlayedList(this.playMusicInfo) this.retryNum = 0 this.restorePlayTime = 0 @@ -646,7 +646,7 @@ export default { if (!this.musicInfo.img) { this.getPic(targetSong).then(() => { - if (targetSong !== this.targetSong) return + if (targetSong.songmid !== this.musicInfo.songmid) return this.musicInfo.img = targetSong.img this.updateMediaSessionInfo() }) @@ -654,7 +654,7 @@ export default { }, setLrc(targetSong) { this.getLrc(targetSong).then(({ lyric, tlyric, lxlyric }) => { - if (targetSong !== this.targetSong) return + if (targetSong.songmid !== this.musicInfo.songmid) return this.musicInfo.lrc = lyric this.musicInfo.tlrc = tlyric this.musicInfo.lxlrc = lxlyric diff --git a/src/renderer/store/modules/download.js b/src/renderer/store/modules/download.js index 572d2d26..f18ddc1a 100644 --- a/src/renderer/store/modules/download.js +++ b/src/renderer/store/modules/download.js @@ -13,9 +13,10 @@ import { assertApiSupport, } from '../../utils' +window.downloadList = [] // state const state = { - list: [], + list: window.downloadList, waitingList: [], downloadStatus: { RUN: 'run', @@ -369,6 +370,7 @@ const actions = { status: state.downloadStatus.WAITING, statusText: '待下载', url: null, + // songmid: musicInfo.songmid, fileName: `${rootState.setting.download.fileName .replace('歌名', musicInfo.name) .replace('歌手', musicInfo.singer)}.${ext}`.replace(filterFileName, ''), @@ -667,7 +669,7 @@ const mutations = { downloadInfo.order = order }, updateDownloadList(state, list) { - state.list = list + state.list = window.downloadList = list }, updateUrl(state, { downloadInfo, url }) { downloadInfo.url = url diff --git a/src/renderer/store/modules/player.js b/src/renderer/store/modules/player.js index ebc2ad0b..12fa73c5 100644 --- a/src/renderer/store/modules/player.js +++ b/src/renderer/store/modules/player.js @@ -40,7 +40,7 @@ const filterList = async({ playedList, listInfo, savePath, commit }) => { canPlayList.push(item) // 排除已播放音乐 - let index = filteredPlayedList.indexOf(item) + let index = filteredPlayedList.findIndex(m => (m.songmid || m.musicInfo.songmid) == item.musicInfo.songmid) if (index > -1) { filteredPlayedList.splice(index, 1) continue @@ -52,7 +52,7 @@ const filterList = async({ playedList, listInfo, savePath, commit }) => { // if (!assertApiSupport(s.source)) return false canPlayList.push(s) - let index = filteredPlayedList.indexOf(s) + let index = filteredPlayedList.findIndex(m => (m.songmid || m.musicInfo.songmid) == s.songmid) if (index > -1) { filteredPlayedList.splice(index, 1) return false @@ -141,12 +141,12 @@ const getLyric = function(musicInfo, retryedSource = [], originMusic) { }) } -let prevPlayIndex +let prevListPlayIndex // getters const getters = { list: state => state.listInfo.list, changePlay: satte => satte.changePlay, - playInfo(state) { + playInfo(state, getters) { if (state.playMusicInfo == null) return { listId: null, playIndex: -1, playListId: null, listPlayIndex: -1, isPlayList: false, musicInfo: null } const playListId = state.listInfo.id let listId = state.playMusicInfo.listId @@ -156,15 +156,28 @@ const getters = { let listPlayIndex = state.playIndex if (listId != '__temp__') { + const currentSongmid = state.playMusicInfo.musicInfo.songmid || state.playMusicInfo.musicInfo.musicInfo.songmid if (isPlayList) { - playIndex = state.listInfo.list.findIndex(m => m.songmid == state.playMusicInfo.musicInfo.songmid) + playIndex = state.listInfo.list.findIndex(m => (m.songmid || m.musicInfo.songmid) == currentSongmid) if (!isTempPlay) listPlayIndex = playIndex + } else if (listId == 'download') { + playIndex = window.downloadList.findIndex(m => m.musicInfo.songmid == currentSongmid) } else { let list = window.allList[listId] - if (list) playIndex = list.list.findIndex(m => m.songmid == state.playMusicInfo.musicInfo.songmid) + if (list) playIndex = list.list.findIndex(m => m.songmid == currentSongmid) } } - if (listPlayIndex > -1) prevPlayIndex = listPlayIndex + if (listPlayIndex >= 0) prevListPlayIndex = listPlayIndex + // if (listPlayIndex < 0) { + // let length = state.listInfo.list.length + // if (length) { + // let index = Math.min(prevListPlayIndex, 0) + // if (index > length - 1) index = length - 1 + // listPlayIndex = prevListPlayIndex = index + // } + // } else { + // prevListPlayIndex = listPlayIndex + // } // console.log({ // listId, // playIndex, @@ -249,12 +262,21 @@ const actions = { async playPrev({ state, rootState, commit, getters }) { const currentListId = state.listInfo.id const currentList = state.listInfo.list + const playInfo = getters.playInfo if (state.playedList.length) { + let currentSongmid + if (state.playMusicInfo.isTempPlay) { + const musicInfo = playInfo.list[playInfo.listPlayIndex] + if (musicInfo) currentSongmid = musicInfo.songmid || musicInfo.musicInfo.songmid + } else { + currentSongmid = state.playMusicInfo.musicInfo.songmid || state.playMusicInfo.musicInfo.musicInfo.songmid + } // 从已播放列表移除播放列表已删除的歌曲 let index - for (index = state.playedList.findIndex(m => m.musicInfo.songmid === state.playMusicInfo.musicInfo.songmid) - 1; index > -1; index--) { + for (index = state.playedList.findIndex(m => (m.musicInfo.songmid || m.musicInfo.musicInfo.songmid) === currentSongmid) - 1; index > -1; index--) { const playMusicInfo = state.playedList[index] - if (playMusicInfo.listId == currentListId && !currentList.some(m => m.songmid === playMusicInfo.musicInfo.songmid)) { + const currentSongmid = playMusicInfo.musicInfo.songmid || playMusicInfo.musicInfo.musicInfo.songmid + if (playMusicInfo.listId == currentListId && !currentList.some(m => (m.songmid || m.musicInfo.songmid) === currentSongmid)) { commit('removePlayedList', index) continue } @@ -274,21 +296,14 @@ const actions = { commit, }) if (!filteredList.length) return commit('setPlayMusicInfo', null) - const playInfo = getters.playInfo - 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 listPlayIndex = playInfo.listPlayIndex + const currentListLength = state.listInfo.list.length - 1 + if (listPlayIndex == -1 && currentListLength) { + listPlayIndex = prevListPlayIndex >= currentListLength ? 0 : prevListPlayIndex + 1 } - let currentIndex = filteredList.findIndex(m => m.songmid == currentMusic.songmid) - if (currentIndex == -1) currentIndex = 0 + let currentIndex = listPlayIndex + if (currentIndex < 0) currentIndex = 0 let nextIndex = currentIndex if (!playInfo.isTempPlay) { switch (rootState.setting.player.togglePlayMethod) { @@ -322,13 +337,22 @@ const actions = { } const currentListId = state.listInfo.id const currentList = state.listInfo.list - console.log(currentListId) + const playInfo = getters.playInfo + if (state.playedList.length) { + let currentSongmid + if (state.playMusicInfo.isTempPlay) { + const musicInfo = currentList[playInfo.listPlayIndex] + if (musicInfo) currentSongmid = musicInfo.songmid || musicInfo.musicInfo.songmid + } else { + currentSongmid = state.playMusicInfo.musicInfo.songmid || state.playMusicInfo.musicInfo.musicInfo.songmid + } // 从已播放列表移除播放列表已删除的歌曲 let index - for (index = state.playedList.findIndex(m => m.musicInfo.songmid === state.playMusicInfo.musicInfo.songmid) + 1; index < state.playedList.length; index++) { + for (index = state.playedList.findIndex(m => (m.musicInfo.songmid || m.musicInfo.musicInfo.songmid) === currentSongmid) + 1; index < state.playedList.length; index++) { const playMusicInfo = state.playedList[index] - if (playMusicInfo.listId == currentListId && !currentList.some(m => m.songmid === playMusicInfo.musicInfo.songmid)) { + const currentSongmid = playMusicInfo.musicInfo.songmid || playMusicInfo.musicInfo.musicInfo.songmid + if (playMusicInfo.listId == currentListId && !currentList.some(m => (m.songmid || m.musicInfo.songmid) === currentSongmid)) { commit('removePlayedList', index) continue } @@ -348,20 +372,12 @@ const actions = { }) if (!filteredList.length) return commit('setPlayMusicInfo', null) - const playInfo = getters.playInfo - 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 listPlayIndex = playInfo.listPlayIndex + const currentListLength = state.listInfo.list.length - 1 + if (listPlayIndex == -1 && currentListLength) { + listPlayIndex = prevListPlayIndex > currentListLength ? currentListLength : prevListPlayIndex - 1 } - let currentIndex = filteredList.findIndex(m => m.songmid == currentMusic.songmid) + const currentIndex = listPlayIndex let nextIndex = currentIndex switch (rootState.setting.player.togglePlayMethod) { @@ -461,7 +477,10 @@ const mutations = { playIndex = -1 } else { let listId = playMusicInfo.listId - if (listId != '__temp__' && !playMusicInfo.isTempPlay && listId === state.listInfo.id) playIndex = state.listInfo.list.findIndex(m => m.songmid == playMusicInfo.musicInfo.songmid) + if (listId != '__temp__' && !playMusicInfo.isTempPlay && listId === state.listInfo.id) { + const currentSongmid = playMusicInfo.musicInfo.songmid || playMusicInfo.musicInfo.musicInfo.songmid + playIndex = state.listInfo.list.findIndex(m => (m.songmid || m.musicInfo.songmid) == currentSongmid) + } } state.playMusicInfo = playMusicInfo diff --git a/src/renderer/views/Download.vue b/src/renderer/views/Download.vue index 4dd190cc..d530c150 100644 --- a/src/renderer/views/Download.vue +++ b/src/renderer/views/Download.vue @@ -182,7 +182,7 @@ export default { }, methods: { ...mapActions('download', ['removeTask', 'removeTasks', 'startTask', 'startTasks', 'pauseTask', 'pauseTasks']), - ...mapMutations('player', ['setList']), + ...mapMutations('player', ['setList', 'setTempPlayList']), listenEvent() { window.eventHub.$on('key_shift_down', this.handle_key_shift_down) window.eventHub.$on('key_shift_up', this.handle_key_shift_up) @@ -312,14 +312,6 @@ export default { case 'remove': this.removeTask(item) break - case 'playLater': - if (this.selectedData.length) { - this.setTempPlayList(this.selectedData.map(s => ({ listId: 'download', musicInfo: s }))) - this.removeAllSelect() - } else { - this.setTempPlayList([{ listId: 'download', musicInfo: item }]) - } - break case 'file': this.handleOpenFolder(item.filePath) break @@ -472,6 +464,14 @@ export default { }) } break + case 'playLater': + if (this.selectedData.length) { + this.setTempPlayList(this.selectedData.map(s => ({ listId: 'download', musicInfo: s }))) + this.removeAllSelect() + } else { + this.setTempPlayList([{ listId: 'download', musicInfo: this.showList[index] }]) + } + break case 'sourceDetail': item = this.showList[index].musicInfo url = musicSdk[item.source].getMusicDetailPageUrl(item)