优化软件启动时恢复上一次播放的歌曲进度功能

pull/392/head
lyswhut 2020-12-11 08:29:30 +08:00
parent f1049169b5
commit 10e5460e39
4 changed files with 48 additions and 12 deletions

View File

@ -2,6 +2,10 @@
- 直接从歌单详情收藏的列表新增同步功能。注意:这将会覆盖本地的目标列表,歌曲将被替换成最新的在线列表
### 优化
- 优化软件启动时恢复上一次播放的歌曲进度功能
### 修复
- 修复MAC平台上下载歌曲封面嵌入无法显示的问题

View File

@ -284,7 +284,7 @@ export default {
l.sourceListId = id
if (!needSave) needSave = true
})
if (needSave) this.this.saveUserList(userList)
if (needSave) this.saveUserList(userList)
} else {
userList = this.userList
}
@ -320,7 +320,9 @@ export default {
initPlayInfo() {
rendererInvoke(NAMES.mainWindow.get_data, 'playInfo').then(info => {
// console.log(info, window.allList)
window.restorePlayInfo = null
if (!info) return
if (info.index < 0) return
if (info.listId) {
const list = window.allList[info.listId]
// console.log(list)

View File

@ -244,9 +244,28 @@ export default {
watch: {
changePlay(n) {
if (!n) return
this.resetChangePlay()
if (window.restorePlayInfo) {
let musicInfo = this.targetSong = this.list[window.restorePlayInfo.index]
this.musicInfo.songmid = musicInfo.songmid
this.musicInfo.singer = musicInfo.singer
this.musicInfo.name = musicInfo.name
this.musicInfo.album = musicInfo.albumName
this.setImg(musicInfo)
this.setLrc(musicInfo)
this.nowPlayTime = this.restorePlayTime = window.restorePlayInfo.time
this.maxPlayTime = window.restorePlayInfo.maxTime || 0
this.handleUpdateWinLyricInfo('music_info', {
songmid: this.musicInfo.songmid,
singer: this.musicInfo.singer,
name: this.musicInfo.name,
album: this.musicInfo.album,
})
window.restorePlayInfo = null
return
}
// console.log('changePlay')
this.handleRemoveMusic()
this.resetChangePlay()
if (this.playIndex < 0) return
this.stopPlay()
this.play()
@ -295,6 +314,7 @@ export default {
if (Math.abs(n - o) > 2) this.isActiveTransition = true
this.savePlayInfo({
time: n,
maxTime: this.maxPlayTime,
listId: this.listId,
list: this.listId == null ? this.list : null,
index: this.playIndex,
@ -377,12 +397,7 @@ export default {
this.clearLoadingTimeout()
this.status = this.statusText = this.$t('core.player.loading')
this.maxPlayTime = audio.duration
if (window.restorePlayInfo) {
audio.currentTime = window.restorePlayInfo.time
window.restorePlayInfo = null
audio.pause()
this.stopPlay()
} else if (this.restorePlayTime) {
if (this.restorePlayTime) {
audio.currentTime = this.restorePlayTime
this.restorePlayTime = 0
}
@ -651,7 +666,13 @@ export default {
)
},
togglePlay() {
if (!audio.src) return
if (!audio.src) {
if (this.restorePlayTime != null) {
if (!this.assertApiSupport(this.targetSong.source)) return this.handleNext()
this.setUrl(this.targetSong)
}
return
}
if (this.isPlay) {
audio.pause()
this.clearBufferTimeout()

View File

@ -9,6 +9,15 @@ for (const source of music.sources) {
sources.push(source)
}
const filterList = list => {
const keys = new Set()
return list.filter(item => {
if (keys.has(item.songmid)) return false
keys.add(item.songmid)
return true
})
}
// state
const state = {
tags: {},
@ -78,7 +87,7 @@ const actions = {
return (
cache.has(key)
? Promise.resolve(cache.get(key))
: music[source].songList.getListDetail(id, page)
: music[source].songList.getListDetail(id, page).then(result => ({ ...result, list: filterList(result.list) }))
).then(result => commit('setListDetail', { result, key, source, id, page }))
},
getListDetailAll({ state, rootState }, { source, id }) {
@ -93,7 +102,7 @@ const actions = {
})
}
return loadData(id, 1).then(result => {
if (result.total <= result.limit) return result.list
if (result.total <= result.limit) return filterList(result.list)
let maxPage = Math.ceil(result.total / result.limit)
const loadDetail = (loadPage = 1) => {
@ -101,7 +110,7 @@ const actions = {
? loadData(id, ++loadPage).then(result => result.list)
: loadData(id, ++loadPage).then(result1 => loadDetail(loadPage).then(result2 => [...result1.list, ...result2]))
}
return loadDetail().then(result2 => [...result.list, ...result2])
return loadDetail().then(result2 => [...result.list, ...result2]).then(list => filterList(list))
})
},
}