From 91ae6bb107284709bf2cd883cc821e9a8d2fb193 Mon Sep 17 00:00:00 2001 From: qier222 Date: Thu, 25 Mar 2021 19:29:40 +0800 Subject: [PATCH] feat: cache next track --- src/utils/Player.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/utils/Player.js b/src/utils/Player.js index 35f6fee..6c4d434 100644 --- a/src/utils/Player.js +++ b/src/utils/Player.js @@ -255,6 +255,7 @@ export default class { return this._getAudioSource(track).then((source) => { if (source) { this._playAudioSource(source, autoplay); + this._cacheNextTrack(); return source; } else { store.dispatch("showToast", `无法播放 ${track.name}`); @@ -265,6 +266,19 @@ export default class { }); }); } + _cacheNextTrack() { + const nextTrack = this._getNextTrack(); + getTrackDetail(nextTrack[0]).then((data) => { + let track = data.songs[0]; + this._getAudioSourceFromCache(String(track.id)) + .then((source) => { + return source ?? this._getAudioSourceFromNetease(track); + }) + .then((source) => { + return source ?? this._getAudioSourceFromUnblockMusic(track); + }); + }); + } _loadSelfFromLocalStorage() { const player = JSON.parse(localStorage.getItem("player")); if (!player) return;