新增播放进度信息保存

pull/389/head
lyswhut 2020-11-19 15:52:00 +08:00
parent b3e3860b23
commit 64a53830e4
3 changed files with 57 additions and 10 deletions

View File

@ -1,6 +1,7 @@
### 新增 ### 新增
- 托盘菜单新增显示、隐藏主界面选项为Linux、MAC版添加托盘菜单 - 托盘菜单新增显示、隐藏主界面选项为Linux、MAC版添加托盘菜单
- 新增播放进度信息保存
### 优化 ### 优化

View File

@ -174,6 +174,9 @@ export default {
...mapMutations('search', { ...mapMutations('search', {
setSearchHistoryList: 'setHistory', setSearchHistoryList: 'setHistory',
}), }),
...mapMutations('player', {
setPlayList: 'setList',
}),
init() { init() {
document.documentElement.style.fontSize = this.windowSizeActive.fontSize document.documentElement.style.fontSize = this.windowSizeActive.fontSize
@ -276,6 +279,7 @@ export default {
if (!loveList.list) loveList.list = [] if (!loveList.list) loveList.list = []
this.initList({ defaultList, loveList, userList }) this.initList({ defaultList, loveList, userList })
this.initDownloadList(downloadList) // this.initDownloadList(downloadList) //
this.initPlayInfo()
}) })
}, },
initDownloadList(downloadList) { initDownloadList(downloadList) {
@ -299,6 +303,27 @@ export default {
} }
}) })
}, },
initPlayInfo() {
rendererInvoke(NAMES.mainWindow.get_data, 'playInfo').then(info => {
// console.log(info, window.allList)
if (!info) return
if (info.listId) {
const list = window.allList[info.listId]
// console.log(list)
if (!list) return
info.list = list.list
}
window.restorePlayInfo = info
this.setPlayList({
list: {
list: info.list,
id: info.listId,
},
index: info.index,
})
})
},
showUpdateModal() { showUpdateModal() {
(this.version.newVersion && this.version.newVersion.history (this.version.newVersion && this.version.newVersion.history
? Promise.resolve(this.version.newVersion) ? Promise.resolve(this.version.newVersion)

View File

@ -87,7 +87,7 @@ div(:class="$style.player")
<script> <script>
import Lyric from 'lrc-file-parser' import Lyric from 'lrc-file-parser'
import { rendererSend, rendererOn, NAMES } from '../../../common/ipc' import { rendererSend, rendererOn, NAMES } from '../../../common/ipc'
import { formatPlayTime2, getRandom, checkPath, setTitle, clipboardWriteText, debounce, assertApiSupport } from '../../utils' import { formatPlayTime2, getRandom, checkPath, setTitle, clipboardWriteText, debounce, throttle, assertApiSupport } from '../../utils'
import { mapGetters, mapActions, mapMutations } from 'vuex' import { mapGetters, mapActions, mapMutations } from 'vuex'
import { requestMsg } from '../../utils/message' import { requestMsg } from '../../utils/message'
import { isMac } from '../../../common/utils' import { isMac } from '../../../common/utils'
@ -130,7 +130,7 @@ export default {
line: 0, line: 0,
}, },
delayNextTimeout: null, delayNextTimeout: null,
audioErrorTime: 0, restorePlayTime: 0,
retryNum: 0, retryNum: 0,
isMac, isMac,
volumeEvent: { volumeEvent: {
@ -195,6 +195,12 @@ export default {
this.handleSaveVolume = debounce(volume => { this.handleSaveVolume = debounce(volume => {
this.setVolume(volume) this.setVolume(volume)
}, 300) }, 300)
this.savePlayInfo = throttle(n => {
rendererSend(NAMES.mainWindow.save_data, {
path: 'playInfo',
data: n,
})
}, 2000)
rendererOn(NAMES.mainWindow.get_lyric_info, (event, info) => { rendererOn(NAMES.mainWindow.get_lyric_info, (event, info) => {
switch (info.action) { switch (info.action) {
@ -287,6 +293,12 @@ export default {
}, },
nowPlayTime(n, o) { nowPlayTime(n, o) {
if (Math.abs(n - o) > 2) this.isActiveTransition = true if (Math.abs(n - o) > 2) this.isActiveTransition = true
this.savePlayInfo({
time: n,
listId: this.listId,
list: this.listId == null ? this.list : null,
index: this.playIndex,
})
}, },
}, },
methods: { methods: {
@ -299,6 +311,7 @@ export default {
'clearPlayedList', 'clearPlayedList',
'setPlayedList', 'setPlayedList',
'removePlayedList', 'removePlayedList',
'setList',
]), ]),
...mapMutations(['setVolume', 'setPlayNextMode', 'setVisibleDesktopLyric', 'setLockDesktopLyric']), ...mapMutations(['setVolume', 'setPlayNextMode', 'setVisibleDesktopLyric', 'setLockDesktopLyric']),
...mapMutations('list', ['updateMusicInfo']), ...mapMutations('list', ['updateMusicInfo']),
@ -348,7 +361,7 @@ export default {
this.stopPlay() this.stopPlay()
if (this.listId != 'download' && audio.error.code !== 1 && this.retryNum < 2) { // URL2URL if (this.listId != 'download' && audio.error.code !== 1 && this.retryNum < 2) { // URL2URL
// console.log(this.retryNum) // console.log(this.retryNum)
if (!this.audioErrorTime) this.audioErrorTime = audio.currentTime // if (!this.restorePlayTime) this.restorePlayTime = audio.currentTime //
this.retryNum++ this.retryNum++
this.setUrl(this.list[this.playIndex], true) this.setUrl(this.list[this.playIndex], true)
this.status = this.statusText = this.$t('core.player.refresh_url') this.status = this.statusText = this.$t('core.player.refresh_url')
@ -360,15 +373,23 @@ export default {
this.addDelayNextTimeout() this.addDelayNextTimeout()
}) })
audio.addEventListener('loadeddata', () => { audio.addEventListener('loadeddata', () => {
// console.log('loadeddata')
this.status = this.statusText = this.$t('core.player.loading')
this.maxPlayTime = audio.duration this.maxPlayTime = audio.duration
if (this.audioErrorTime) { if (window.restorePlayInfo) {
audio.currentTime = this.audioErrorTime audio.currentTime = window.restorePlayInfo.time
this.audioErrorTime = 0 window.restorePlayInfo = null
audio.pause()
this.stopPlay()
} else if (this.restorePlayTime) {
audio.currentTime = this.restorePlayTime
this.restorePlayTime = 0
} }
if (!this.targetSong.interval && this.listId != 'download') this.updateMusicInfo({ id: this.listId, index: this.playIndex, data: { interval: formatPlayTime2(this.maxPlayTime) } }) if (!this.targetSong.interval && this.listId != 'download') this.updateMusicInfo({ id: this.listId, index: this.playIndex, data: { interval: formatPlayTime2(this.maxPlayTime) } })
this.status = this.statusText = this.$t('core.player.loading')
}) })
audio.addEventListener('loadstart', () => { audio.addEventListener('loadstart', () => {
// console.log('loadstart')
this.startBuffering()
this.status = this.statusText = this.$t('core.player.loading') this.status = this.statusText = this.$t('core.player.loading')
}) })
audio.addEventListener('canplay', () => { audio.addEventListener('canplay', () => {
@ -382,7 +403,7 @@ export default {
this.clearBufferTimeout() this.clearBufferTimeout()
} }
// if (this.musicInfo.lrc) window.lrc.play(audio.currentTime * 1000) // if (this.musicInfo.lrc) window.lrc.play(audio.currentTime * 1000)
this.status = this.statusText = this.$t('core.player.loading') this.status = this.statusText = ''
}) })
// audio.addEventListener('canplaythrough', () => { // audio.addEventListener('canplaythrough', () => {
// console.log('') // console.log('')
@ -432,7 +453,7 @@ export default {
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) if (this.setting.player.togglePlayMethod == 'random') this.setPlayedList(targetSong)
this.retryNum = 0 this.retryNum = 0
this.audioErrorTime = 0 this.restorePlayTime = 0
if (this.listId == 'download') { if (this.listId == 'download') {
const filePath = path.join(this.setting.download.savePath, targetSong.fileName) const filePath = path.join(this.setting.download.savePath, targetSong.fileName)
@ -613,7 +634,7 @@ export default {
setProgress(pregress) { setProgress(pregress) {
if (!audio.src) return if (!audio.src) return
const time = pregress * this.maxPlayTime const time = pregress * this.maxPlayTime
if (this.audioErrorTime) this.audioErrorTime = time if (this.restorePlayTime) this.restorePlayTime = time
if (this.mediaBuffer.playTime) { if (this.mediaBuffer.playTime) {
this.clearBufferTimeout() this.clearBufferTimeout()
this.mediaBuffer.playTime = time this.mediaBuffer.playTime = time