From b80c509d1bae39d1658a6ec7f8602fd8a3569886 Mon Sep 17 00:00:00 2001 From: qier222 Date: Fri, 29 Jan 2021 16:18:01 +0800 Subject: [PATCH] feat: remember the current track playing time --- src/utils/Player.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utils/Player.js b/src/utils/Player.js index ad7a0ce..e8f6f8c 100644 --- a/src/utils/Player.js +++ b/src/utils/Player.js @@ -103,7 +103,14 @@ export default class { _init() { Howler.autoUnlock = false; this._loadSelfFromLocalStorage(); - this._replaceCurrentTrack(this._currentTrack.id, false); // update audio source and init howler + this._replaceCurrentTrack(this._currentTrack.id, false).then(() => { + this._howler.seek(localStorage.getItem("playerCurrentTrackTime") ?? 0); + setInterval( + () => + localStorage.setItem("playerCurrentTrackTime", this._howler.seek()), + 1000 + ); + }); // update audio source and init howler this._initMediaSession(); Howler.volume(this.volume); } @@ -208,7 +215,7 @@ export default class { this._currentTrack = track; this._updateMediaSessionMetaData(track); document.title = `${track.name} ยท ${track.ar[0].name} - YesPlayMusic`; - this._getAudioSource(track).then((source) => { + return this._getAudioSource(track).then((source) => { if (source) { this._playAudioSource(source, autoplay); return source; @@ -319,7 +326,7 @@ export default class { } seek(time = null) { if (time !== null) this._howler.seek(time); - return this._howler.seek(); + return this._howler === null ? 0 : this._howler.seek(); } mute() { if (this.volume === 0) {