优化播放下载列表时的切歌性能

pull/930/merge
lyswhut 2022-03-20 01:47:09 +08:00
parent 8b988b227b
commit 9bf33fdb25
1 changed files with 76 additions and 30 deletions

View File

@ -36,8 +36,10 @@ const playMusic = () => {
window.eventHub.emit(eventPlayerNames.playMusic) window.eventHub.emit(eventPlayerNames.playMusic)
} }
const filterList = async({ playedList, listInfo, savePath, commit }) => { const filterList = async({ playedList, listInfo, savePath, commit, isCheckFile }) => {
// if (this.list.listName === null) return // if (this.list.listName === null) return
// console.log(isCheckFile)
if (isCheckFile) {
let list let list
let canPlayList = [] let canPlayList = []
const filteredPlayedList = playedList.filter(({ listId, isTempPlay }) => listInfo.id === listId && !isTempPlay).map(({ musicInfo }) => musicInfo) const filteredPlayedList = playedList.filter(({ listId, isTempPlay }) => listInfo.id === listId && !isTempPlay).map(({ musicInfo }) => musicInfo)
@ -75,6 +77,27 @@ const filterList = async({ playedList, listInfo, savePath, commit }) => {
return canPlayList return canPlayList
} }
return list return list
} else {
let canPlayList = []
const filteredPlayedList = playedList.filter(({ listId, isTempPlay }) => listInfo.id === listId && !isTempPlay).map(({ musicInfo }) => musicInfo)
const list = listInfo.list.filter(s => {
// if (!assertApiSupport(s.source)) return false
canPlayList.push(s)
let index = filteredPlayedList.findIndex(m => m.songmid == s.songmid)
if (index > -1) {
filteredPlayedList.splice(index, 1)
return false
}
return true
})
if (!list.length && playedList.length) {
commit('clearPlayedList')
return canPlayList
}
return list
}
} }
const getMusicUrl = function(musicInfo, type, onToggleSource, retryedSource = [], originMusic) { const getMusicUrl = function(musicInfo, type, onToggleSource, retryedSource = [], originMusic) {
@ -221,7 +244,7 @@ const actions = {
}) })
}, },
async playPrev({ state, rootState, commit, getters }) { async playPrev({ state, rootState, commit, getters }, { findNum = 0, excludeList = [] } = {}) {
const currentListId = playInfo.playListId const currentListId = playInfo.playListId
const currentList = getList(currentListId) const currentList = getList(currentListId)
if (playedList.length) { if (playedList.length) {
@ -251,11 +274,13 @@ const actions = {
} }
} }
const isCheckFile = findNum > 2
let filteredList = await filterList({ let filteredList = await filterList({
listInfo: { id: currentListId, list: currentList }, listInfo: { id: currentListId, list: currentList },
playedList, playedList: excludeList.length ? [...playedList, ...excludeList] : playedList,
savePath: rootState.setting.download.savePath, savePath: rootState.setting.download.savePath,
commit, commit,
isCheckFile,
}) })
if (!filteredList.length) return commit('setPlayMusicInfo', { listId: null, musicInfo: null }) if (!filteredList.length) return commit('setPlayMusicInfo', { listId: null, musicInfo: null })
@ -280,13 +305,23 @@ const actions = {
if (nextIndex < 0) return if (nextIndex < 0) return
} }
commit('setPlayMusicInfo', { const nextPlayMusicInfo = {
musicInfo: filteredList[nextIndex], musicInfo: filteredList[nextIndex],
listId: currentListId, listId: currentListId,
}) }
if (currentListId == 'download' && !isCheckFile) {
if (!await checkPath(path.join(rootState.setting.download.savePath, nextPlayMusicInfo.musicInfo.metadata.fileName)) || !nextPlayMusicInfo.musicInfo.isComplate || /\.ape$/.test(nextPlayMusicInfo.musicInfo.metadata.fileName)) {
excludeList.push(nextPlayMusicInfo)
// console.log('findNum', findNum)
return this.dispatch('player/playPrev', { findNum: findNum + 1, excludeList })
}
}
commit('setPlayMusicInfo', nextPlayMusicInfo)
playMusic() playMusic()
}, },
async playNext({ state, rootState, commit, getters }) { async playNext({ state, rootState, commit, getters }, { findNum = 0, excludeList = [] } = {}) {
if (tempPlayList.length) { if (tempPlayList.length) {
const playMusicInfo = tempPlayList[0] const playMusicInfo = tempPlayList[0]
commit('removeTempPlayList', 0) commit('removeTempPlayList', 0)
@ -325,11 +360,13 @@ const actions = {
return return
} }
} }
const isCheckFile = findNum > 2
let filteredList = await filterList({ let filteredList = await filterList({
listInfo: { id: currentListId, list: currentList }, listInfo: { id: currentListId, list: currentList },
playedList, playedList: excludeList.length ? [...playedList, ...excludeList] : playedList,
savePath: rootState.setting.download.savePath, savePath: rootState.setting.download.savePath,
commit, commit,
isCheckFile,
}) })
if (!filteredList.length) return commit('setPlayMusicInfo', { listId: null, musicInfo: null }) if (!filteredList.length) return commit('setPlayMusicInfo', { listId: null, musicInfo: null })
@ -355,10 +392,19 @@ const actions = {
} }
if (nextIndex < 0) return if (nextIndex < 0) return
commit('setPlayMusicInfo', { const nextPlayMusicInfo = {
musicInfo: filteredList[nextIndex], musicInfo: filteredList[nextIndex],
listId: currentListId, listId: currentListId,
}) }
if (currentListId == 'download' && !isCheckFile) {
if (!await checkPath(path.join(rootState.setting.download.savePath, nextPlayMusicInfo.musicInfo.metadata.fileName)) || !nextPlayMusicInfo.musicInfo.isComplate || /\.ape$/.test(nextPlayMusicInfo.musicInfo.metadata.fileName)) {
excludeList.push(nextPlayMusicInfo)
// console.log('findNum', findNum)
return this.dispatch('player/playNext', { findNum: findNum + 1, excludeList })
}
}
commit('setPlayMusicInfo', nextPlayMusicInfo)
playMusic() playMusic()
}, },
} }