From fbf695eb160a9b6fa0252cb15cfdd73eaf2da99a Mon Sep 17 00:00:00 2001 From: pan93412 Date: Wed, 16 Mar 2022 15:02:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(utils/player):=20=E6=92=AD=E6=94=BE?= =?UTF-8?q?=E3=80=81=E6=9A=AB=E5=81=9C=E6=99=82=E6=B7=A1=E5=85=A5=E6=B7=A1?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/Player.js | 48 ++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/utils/Player.js b/src/utils/Player.js index 908d3e8..d407e72 100644 --- a/src/utils/Player.js +++ b/src/utils/Player.js @@ -11,6 +11,8 @@ import { isAccountLoggedIn } from '@/utils/auth'; import { trackUpdateNowPlaying, trackScrobble } from '@/api/lastfm'; import { isCreateMpris, isCreateTray } from '@/utils/platform'; +const PLAY_PAUSE_FADE_DURATION = 200; + const electron = process.env.IS_ELECTRON === true ? window.require('electron') : null; const ipcRenderer = @@ -649,28 +651,38 @@ export default class { } pause() { - this._howler?.pause(); - this._setPlaying(false); - setTitle(null); - this._pauseDiscordPresence(this._currentTrack); + this._howler?.fade(this.volume, 0, PLAY_PAUSE_FADE_DURATION); + + this._howler?.once('fade', () => { + this._howler?.pause(); + this._setPlaying(false); + setTitle(null); + this._pauseDiscordPresence(this._currentTrack); + }); } play() { if (this._howler?.playing()) return; + this._howler?.play(); - this._setPlaying(true); - if (this._currentTrack.name) { - setTitle(this._currentTrack); - } - this._playDiscordPresence(this._currentTrack, this.seek()); - if (store.state.lastfm.key !== undefined) { - trackUpdateNowPlaying({ - artist: this.currentTrack.ar[0].name, - track: this.currentTrack.name, - album: this.currentTrack.al.name, - trackNumber: this.currentTrack.no, - duration: ~~(this.currentTrack.dt / 1000), - }); - } + + this._howler?.once('play', () => { + this._howler?.fade(0, this.volume, PLAY_PAUSE_FADE_DURATION); + + this._setPlaying(true); + if (this._currentTrack.name) { + setTitle(this._currentTrack); + } + this._playDiscordPresence(this._currentTrack, this.seek()); + if (store.state.lastfm.key !== undefined) { + trackUpdateNowPlaying({ + artist: this.currentTrack.ar[0].name, + track: this.currentTrack.name, + album: this.currentTrack.al.name, + trackNumber: this.currentTrack.no, + duration: ~~(this.currentTrack.dt / 1000), + }); + } + }); } playOrPause() { if (this._howler?.playing()) {