新增播放自动换源功能

This commit is contained in:
lyswhut
2021-01-09 00:45:15 +08:00
parent 6b7d2ea657
commit 9a1a537bfd
21 changed files with 90 additions and 8 deletions
+26 -6
View File
@@ -92,6 +92,7 @@ import { mapGetters, mapActions, mapMutations } from 'vuex'
import { requestMsg } from '../../utils/message'
import { isMac } from '../../../common/utils'
import { player as eventPlayerNames } from '../../../common/hotKey'
import musicSdk from '@renderer/utils/music'
import path from 'path'
let audio
@@ -694,20 +695,39 @@ export default {
if (highQuality && songInfo._types['320k'] && list && list.includes('320k')) type = '320k'
return type
},
setUrl(targetSong, isRefresh, isRetryed = false) {
setUrl(targetSong, isRefresh, isRetryed = false, retryedSource = [], originMusic = null) {
if (!retryedSource.includes(targetSong.source)) retryedSource.push(targetSong.source)
let type = this.getPlayType(this.setting.player.highQuality, targetSong)
this.musicInfo.url = targetSong.typeUrl[type]
this.status = this.statusText = this.$t('core.player.geting_url')
return this.getUrl({ musicInfo: targetSong, type, isRefresh }).then(() => {
return this.getUrl({ musicInfo: targetSong, originMusic, type, isRefresh }).then(() => {
audio.src = this.musicInfo.url = targetSong.typeUrl[type]
}).catch(err => {
// console.log('err', err.message)
if (err.message == requestMsg.cancelRequest) return
if (!isRetryed) return this.setUrl(targetSong, isRefresh, true)
this.status = this.statusText = err.message
this.addDelayNextTimeout()
return Promise.reject(err)
if (!isRetryed) return this.setUrl(targetSong, isRefresh, true, retryedSource, originMusic)
if (!originMusic) originMusic = targetSong
this.status = this.statusText = 'Try toggle source...'
return (originMusic.otherSource ? Promise.resolve(originMusic.otherSource) : musicSdk.findMusic(originMusic)).then(res => {
this.updateMusicInfo({ id: this.listId, index: this.playIndex, data: { otherSource: res } })
return res
}).then(otherSource => {
console.log('find otherSource', otherSource)
if (otherSource.length) {
for (const item of otherSource) {
if (retryedSource.includes(item.source)) continue
console.log('try toggle to: ', item.source, item.name, item.singer, item.interval)
return this.setUrl(item, isRefresh, false, retryedSource, originMusic)
}
}
this.status = this.statusText = err.message
this.addDelayNextTimeout()
return Promise.reject(err)
})
})
},
setImg(targetSong) {