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

This commit is contained in:
lyswhut
2020-12-11 08:29:30 +08:00
parent f1049169b5
commit 10e5460e39
4 changed files with 48 additions and 12 deletions
+29 -8
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()