优化播放下载列表时的切歌性能
parent
8b988b227b
commit
9bf33fdb25
|
@ -36,29 +36,52 @@ 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
|
||||||
let list
|
// console.log(isCheckFile)
|
||||||
let canPlayList = []
|
if (isCheckFile) {
|
||||||
const filteredPlayedList = playedList.filter(({ listId, isTempPlay }) => listInfo.id === listId && !isTempPlay).map(({ musicInfo }) => musicInfo)
|
let list
|
||||||
if (listInfo.id == 'download') {
|
let canPlayList = []
|
||||||
list = []
|
const filteredPlayedList = playedList.filter(({ listId, isTempPlay }) => listInfo.id === listId && !isTempPlay).map(({ musicInfo }) => musicInfo)
|
||||||
for (const item of listInfo.list) {
|
if (listInfo.id == 'download') {
|
||||||
const filePath = path.join(savePath, item.metadata.fileName)
|
list = []
|
||||||
if (!await checkPath(filePath) || !item.isComplate || /\.ape$/.test(filePath)) continue
|
for (const item of listInfo.list) {
|
||||||
|
const filePath = path.join(savePath, item.metadata.fileName)
|
||||||
|
if (!await checkPath(filePath) || !item.isComplate || /\.ape$/.test(filePath)) continue
|
||||||
|
|
||||||
canPlayList.push(item)
|
canPlayList.push(item)
|
||||||
|
|
||||||
// 排除已播放音乐
|
// 排除已播放音乐
|
||||||
let index = filteredPlayedList.findIndex(m => m.songmid == item.songmid)
|
let index = filteredPlayedList.findIndex(m => m.songmid == item.songmid)
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
filteredPlayedList.splice(index, 1)
|
filteredPlayedList.splice(index, 1)
|
||||||
continue
|
continue
|
||||||
|
}
|
||||||
|
list.push(item)
|
||||||
}
|
}
|
||||||
list.push(item)
|
} else {
|
||||||
|
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
|
||||||
} else {
|
} else {
|
||||||
list = listInfo.list.filter(s => {
|
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
|
// if (!assertApiSupport(s.source)) return false
|
||||||
canPlayList.push(s)
|
canPlayList.push(s)
|
||||||
|
|
||||||
|
@ -69,12 +92,12 @@ const filterList = async({ playedList, listInfo, savePath, commit }) => {
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
if (!list.length && playedList.length) {
|
||||||
|
commit('clearPlayedList')
|
||||||
|
return canPlayList
|
||||||
|
}
|
||||||
|
return list
|
||||||
}
|
}
|
||||||
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()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue