diff --git a/publish/changeLog.md b/publish/changeLog.md index e67a092f..3017f024 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -9,3 +9,4 @@ - 桌面歌词当前播放行改为上下居中 - 为区分静音状态,静音时音量条会变淡,调整音量条时将会取消静音 +- 优化随机播放机制,现在通过`下一曲`切换歌曲时,直到播放完整个列表之前将不会再随机到之前播放过的歌曲,并且通过`上一曲`可以正确播放上一首歌曲 diff --git a/src/renderer/components/core/Player.vue b/src/renderer/components/core/Player.vue index d864765f..c8c7da81 100644 --- a/src/renderer/components/core/Player.vue +++ b/src/renderer/components/core/Player.vue @@ -116,7 +116,7 @@ export default { }, computed: { ...mapGetters(['setting']), - ...mapGetters('player', ['list', 'playIndex', 'changePlay', 'listId', 'isShowPlayerDetail']), + ...mapGetters('player', ['list', 'playIndex', 'changePlay', 'listId', 'isShowPlayerDetail', 'playedList']), // pic() { // return this.musicInfo.img ? this.musicInfo.img : '' // }, @@ -194,6 +194,8 @@ export default { }, 'setting.player.togglePlayMethod'(n) { audio.loop = n === 'singleLoop' + if (this.playedList.length) this.clearPlayedList() + if (n == 'random' && this.playIndex > -1) this.setPlayedList(this.list[this.playIndex]) }, 'setting.player.isMute'(n) { audio.muted = n @@ -238,6 +240,9 @@ export default { 'fixPlayIndex', 'resetChangePlay', 'visiblePlayerDetail', + 'clearPlayedList', + 'setPlayedList', + 'removePlayedList', ]), ...mapMutations(['setVolume']), ...mapMutations('list', ['updateMusicInfo']), @@ -369,6 +374,7 @@ export default { console.log('play', this.playIndex) this.checkDelayNextTimeout() let targetSong = this.targetSong = this.list[this.playIndex] + if (this.setting.player.togglePlayMethod == 'random') this.setPlayedList(targetSong) this.retryNum = 0 this.audioErrorTime = 0 @@ -420,20 +426,51 @@ export default { async filterList() { // if (this.list.listName === null) return let list + let playedList = [...this.playedList] if (this.listId == 'download') { list = [] for (const item of this.list) { const filePath = path.join(this.setting.download.savePath, item.fileName) if (!await checkPath(filePath) || !item.isComplate || /\.ape$/.test(filePath)) continue + + let index = playedList.indexOf(item) + if (index > -1) { + playedList.splice(index, 1) + continue + } list.push(item) } } else { - list = this.list.filter(s => this.assertApiSupport(s.source)) + list = this.list.filter(s => { + let index = playedList.indexOf(s) + if (index > -1) { + playedList.splice(index, 1) + return false + } + return this.assertApiSupport(s.source) + }) + } + if (!list.length && this.playedList.length) { + this.clearPlayedList() + return this.filterList() } return list }, async handlePrev() { // console.log(playIndex) + if (this.setting.player.togglePlayMethod == 'random' && this.playedList.length) { + let index = this.playedList.indexOf(this.targetSong) + index -= 1 + if (index > -1) { + let listIndex = this.list.indexOf(this.playedList[index]) + if (listIndex < 0) { + this.removePlayedList(index) + return this.handlePrev() + } + this.setPlayIndex(listIndex) + return + } + } let list = await this.filterList() if (!list.length) return this.setPlayIndex(-1) let playIndex = list.indexOf(this.list[this.playIndex]) @@ -455,6 +492,20 @@ export default { }, async handleNext() { // if (this.list.listName === null) return + // eslint-disable-next-line no-debugger + if (this.setting.player.togglePlayMethod == 'random' && this.playedList.length) { + let index = this.playedList.indexOf(this.targetSong) + index += 1 + if (index < this.playedList.length) { + let listIndex = this.list.indexOf(this.playedList[index]) + if (listIndex < 0) { + this.removePlayedList(index) + return this.handleNext() + } + this.setPlayIndex(listIndex) + return + } + } let list = await this.filterList() if (!list.length) return this.setPlayIndex(-1) let playIndex = list.indexOf(this.list[this.playIndex]) diff --git a/src/renderer/store/modules/player.js b/src/renderer/store/modules/player.js index e61ee64f..84da8ded 100644 --- a/src/renderer/store/modules/player.js +++ b/src/renderer/store/modules/player.js @@ -9,6 +9,7 @@ const state = { playIndex: -1, changePlay: false, isShowPlayerDetail: false, + playedList: [], } let urlRequest @@ -22,6 +23,7 @@ const getters = { changePlay: satte => satte.changePlay, playIndex: state => state.playIndex, isShowPlayerDetail: state => state.isShowPlayerDetail, + playedList: state => state.playedList, } // actions @@ -84,6 +86,7 @@ const mutations = { state.listInfo = list state.playIndex = index state.changePlay = true + if (state.playedList.length) this.commit('player/clearPlayedList') }, setPlayIndex(state, index) { state.playIndex = index @@ -96,6 +99,16 @@ const mutations = { resetChangePlay(state) { state.changePlay = false }, + setPlayedList(state, item) { + if (state.playedList.includes(item)) return + state.playedList.push(item) + }, + removePlayedList(state, index) { + state.playedList.splice(index, 1) + }, + clearPlayedList(state) { + state.playedList = [] + }, visiblePlayerDetail(state, visible) { state.isShowPlayerDetail = visible },