优化随机播放机制
parent
6606edafb9
commit
85c683b714
|
@ -9,3 +9,4 @@
|
||||||
|
|
||||||
- 桌面歌词当前播放行改为上下居中
|
- 桌面歌词当前播放行改为上下居中
|
||||||
- 为区分静音状态,静音时音量条会变淡,调整音量条时将会取消静音
|
- 为区分静音状态,静音时音量条会变淡,调整音量条时将会取消静音
|
||||||
|
- 优化随机播放机制,现在通过`下一曲`切换歌曲时,直到播放完整个列表之前将不会再随机到之前播放过的歌曲,并且通过`上一曲`可以正确播放上一首歌曲
|
||||||
|
|
|
@ -116,7 +116,7 @@ export default {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters(['setting']),
|
...mapGetters(['setting']),
|
||||||
...mapGetters('player', ['list', 'playIndex', 'changePlay', 'listId', 'isShowPlayerDetail']),
|
...mapGetters('player', ['list', 'playIndex', 'changePlay', 'listId', 'isShowPlayerDetail', 'playedList']),
|
||||||
// pic() {
|
// pic() {
|
||||||
// return this.musicInfo.img ? this.musicInfo.img : ''
|
// return this.musicInfo.img ? this.musicInfo.img : ''
|
||||||
// },
|
// },
|
||||||
|
@ -194,6 +194,8 @@ export default {
|
||||||
},
|
},
|
||||||
'setting.player.togglePlayMethod'(n) {
|
'setting.player.togglePlayMethod'(n) {
|
||||||
audio.loop = n === 'singleLoop'
|
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) {
|
'setting.player.isMute'(n) {
|
||||||
audio.muted = n
|
audio.muted = n
|
||||||
|
@ -238,6 +240,9 @@ export default {
|
||||||
'fixPlayIndex',
|
'fixPlayIndex',
|
||||||
'resetChangePlay',
|
'resetChangePlay',
|
||||||
'visiblePlayerDetail',
|
'visiblePlayerDetail',
|
||||||
|
'clearPlayedList',
|
||||||
|
'setPlayedList',
|
||||||
|
'removePlayedList',
|
||||||
]),
|
]),
|
||||||
...mapMutations(['setVolume']),
|
...mapMutations(['setVolume']),
|
||||||
...mapMutations('list', ['updateMusicInfo']),
|
...mapMutations('list', ['updateMusicInfo']),
|
||||||
|
@ -369,6 +374,7 @@ export default {
|
||||||
console.log('play', this.playIndex)
|
console.log('play', this.playIndex)
|
||||||
this.checkDelayNextTimeout()
|
this.checkDelayNextTimeout()
|
||||||
let targetSong = this.targetSong = this.list[this.playIndex]
|
let targetSong = this.targetSong = this.list[this.playIndex]
|
||||||
|
if (this.setting.player.togglePlayMethod == 'random') this.setPlayedList(targetSong)
|
||||||
this.retryNum = 0
|
this.retryNum = 0
|
||||||
this.audioErrorTime = 0
|
this.audioErrorTime = 0
|
||||||
|
|
||||||
|
@ -420,20 +426,51 @@ export default {
|
||||||
async filterList() {
|
async filterList() {
|
||||||
// if (this.list.listName === null) return
|
// if (this.list.listName === null) return
|
||||||
let list
|
let list
|
||||||
|
let playedList = [...this.playedList]
|
||||||
if (this.listId == 'download') {
|
if (this.listId == 'download') {
|
||||||
list = []
|
list = []
|
||||||
for (const item of this.list) {
|
for (const item of this.list) {
|
||||||
const filePath = path.join(this.setting.download.savePath, item.fileName)
|
const filePath = path.join(this.setting.download.savePath, item.fileName)
|
||||||
if (!await checkPath(filePath) || !item.isComplate || /\.ape$/.test(filePath)) continue
|
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)
|
list.push(item)
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
return list
|
||||||
},
|
},
|
||||||
async handlePrev() {
|
async handlePrev() {
|
||||||
// console.log(playIndex)
|
// 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()
|
let list = await this.filterList()
|
||||||
if (!list.length) return this.setPlayIndex(-1)
|
if (!list.length) return this.setPlayIndex(-1)
|
||||||
let playIndex = list.indexOf(this.list[this.playIndex])
|
let playIndex = list.indexOf(this.list[this.playIndex])
|
||||||
|
@ -455,6 +492,20 @@ export default {
|
||||||
},
|
},
|
||||||
async handleNext() {
|
async handleNext() {
|
||||||
// if (this.list.listName === null) return
|
// 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()
|
let list = await this.filterList()
|
||||||
if (!list.length) return this.setPlayIndex(-1)
|
if (!list.length) return this.setPlayIndex(-1)
|
||||||
let playIndex = list.indexOf(this.list[this.playIndex])
|
let playIndex = list.indexOf(this.list[this.playIndex])
|
||||||
|
|
|
@ -9,6 +9,7 @@ const state = {
|
||||||
playIndex: -1,
|
playIndex: -1,
|
||||||
changePlay: false,
|
changePlay: false,
|
||||||
isShowPlayerDetail: false,
|
isShowPlayerDetail: false,
|
||||||
|
playedList: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
let urlRequest
|
let urlRequest
|
||||||
|
@ -22,6 +23,7 @@ const getters = {
|
||||||
changePlay: satte => satte.changePlay,
|
changePlay: satte => satte.changePlay,
|
||||||
playIndex: state => state.playIndex,
|
playIndex: state => state.playIndex,
|
||||||
isShowPlayerDetail: state => state.isShowPlayerDetail,
|
isShowPlayerDetail: state => state.isShowPlayerDetail,
|
||||||
|
playedList: state => state.playedList,
|
||||||
}
|
}
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
|
@ -84,6 +86,7 @@ const mutations = {
|
||||||
state.listInfo = list
|
state.listInfo = list
|
||||||
state.playIndex = index
|
state.playIndex = index
|
||||||
state.changePlay = true
|
state.changePlay = true
|
||||||
|
if (state.playedList.length) this.commit('player/clearPlayedList')
|
||||||
},
|
},
|
||||||
setPlayIndex(state, index) {
|
setPlayIndex(state, index) {
|
||||||
state.playIndex = index
|
state.playIndex = index
|
||||||
|
@ -96,6 +99,16 @@ const mutations = {
|
||||||
resetChangePlay(state) {
|
resetChangePlay(state) {
|
||||||
state.changePlay = false
|
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) {
|
visiblePlayerDetail(state, visible) {
|
||||||
state.isShowPlayerDetail = visible
|
state.isShowPlayerDetail = visible
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue