diff --git a/src/renderer/components/core/Player.vue b/src/renderer/components/core/Player.vue index 835da8bb..1e19a90f 100644 --- a/src/renderer/components/core/Player.vue +++ b/src/renderer/components/core/Player.vue @@ -604,37 +604,21 @@ export default { if (highQuality && songInfo._types['320k'] && list && list.includes('320k')) type = '320k' return type }, - setUrl(targetSong, isRefresh, isRetryed = false, retryedSource = [], originMusic = null) { - if (!retryedSource.includes(targetSong.source)) retryedSource.push(targetSong.source) - + setUrl(targetSong, isRefresh, isRetryed = false) { let type = this.getPlayType(this.setting.player.highQuality, targetSong) // this.musicInfo.url = await getMusicUrl(targetSong, type) this.status = this.statusText = this.$t('core.player.geting_url') - return this.getUrl({ musicInfo: targetSong, originMusic, type, isRefresh }).then(url => { - if ((targetSong !== this.targetSong && originMusic !== this.targetSong) || this.isPlay) return + return this.getUrl({ musicInfo: targetSong, type, isRefresh }).then(url => { + if (targetSong !== this.targetSong || this.isPlay) return audio.src = this.musicInfo.url = url }).catch(err => { // console.log('err', err.message) if (err.message == requestMsg.cancelRequest) return - if (!isRetryed) return this.setUrl(targetSong, isRefresh, true, retryedSource, originMusic) - if (!originMusic) originMusic = targetSong - - this.status = this.statusText = 'Try toggle source...' - - return this.getOtherSource(originMusic).then(otherSource => { - console.log('find otherSource', otherSource) - if (otherSource.length) { - for (const item of otherSource) { - if (retryedSource.includes(item.source) || !this.assertApiSupport(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) - }) + if (!isRetryed) return this.setUrl(targetSong, isRefresh, true) + this.status = this.statusText = err.message + this.addDelayNextTimeout() + return Promise.reject(err) }) }, setImg(targetSong) { diff --git a/src/renderer/store/modules/download.js b/src/renderer/store/modules/download.js index f424398e..2dc688b5 100644 --- a/src/renderer/store/modules/download.js +++ b/src/renderer/store/modules/download.js @@ -165,12 +165,12 @@ const handleGetMusicUrl = function(musicInfo, type, retryedSource = [], originMu reqPromise = Promise.reject(err) } return reqPromise.catch(err => { - if (!retryedSource.includes(musicInfo.source) || !assertApiSupport(musicInfo.source)) retryedSource.push(musicInfo.source) + if (!retryedSource.includes(musicInfo.source)) retryedSource.push(musicInfo.source) return this.dispatch('list/getOtherSource', originMusic).then(otherSource => { console.log('find otherSource', otherSource) if (otherSource.length) { for (const item of otherSource) { - if (retryedSource.includes(item.source)) continue + if (retryedSource.includes(item.source) || !assertApiSupport(item.source)) continue console.log('try toggle to: ', item.source, item.name, item.singer, item.interval) return handleGetMusicUrl.call(this, item, type, retryedSource, originMusic) } diff --git a/src/renderer/store/modules/player.js b/src/renderer/store/modules/player.js index 36a0a502..b32239f0 100644 --- a/src/renderer/store/modules/player.js +++ b/src/renderer/store/modules/player.js @@ -6,7 +6,8 @@ import { getLyric as getStoreLyric, setLyric, setMusicUrl, - getMusicUrl, + getMusicUrl as getStoreMusicUrl, + assertApiSupport, } from '../../utils' // state @@ -66,6 +67,31 @@ const filterList = async({ playedList, listInfo, savePath, commit }) => { return list } +const getMusicUrl = function(musicInfo, type, retryedSource = [], originMusic) { + // console.log(musicInfo.source) + if (!originMusic) originMusic = musicInfo + let reqPromise + try { + reqPromise = music[musicInfo.source].getMusicUrl(musicInfo, type).promise + } catch (err) { + reqPromise = Promise.reject(err) + } + return reqPromise.catch(err => { + if (!retryedSource.includes(musicInfo.source)) retryedSource.push(musicInfo.source) + return this.dispatch('list/getOtherSource', originMusic).then(otherSource => { + console.log('find otherSource', otherSource) + if (otherSource.length) { + for (const item of otherSource) { + if (retryedSource.includes(item.source) || !assertApiSupport(item.source)) continue + console.log('try toggle to: ', item.source, item.name, item.singer, item.interval) + return getMusicUrl.call(this, item, type, retryedSource, originMusic) + } + } + return Promise.reject(err) + }) + }) +} + const getPic = function(musicInfo, retryedSource = [], originMusic) { // console.log(musicInfo.source) if (!originMusic) originMusic = musicInfo @@ -163,24 +189,17 @@ const getters = { // actions const actions = { - async getUrl({ commit, state }, { musicInfo, originMusic, type, isRefresh }) { + async getUrl({ commit, state }, { musicInfo, type, isRefresh }) { if (!musicInfo._types[type]) { // 兼容旧版酷我源搜索列表过滤128k音质的bug if (!(musicInfo.source == 'kw' && type == '128k')) throw new Error('该歌曲没有可播放的音频') // return Promise.reject(new Error('该歌曲没有可播放的音频')) } - const cachedUrl = await getMusicUrl(musicInfo, type) + const cachedUrl = await getStoreMusicUrl(musicInfo, type) if (cachedUrl && !isRefresh) return cachedUrl - let reqPromise - try { - reqPromise = music[musicInfo.source].getMusicUrl(musicInfo, type).promise - } catch (err) { - reqPromise = Promise.reject(err) - } - return reqPromise.then(({ url }) => { - if (originMusic) commit('setUrl', { musicInfo: originMusic, url, type }) + return getMusicUrl.call(this, musicInfo, type).then(({ url }) => { commit('setUrl', { musicInfo, url, type }) return url }).catch(err => {