diff --git a/src/electron/mpris.js b/src/electron/mpris.js index 92b74a6..c6cfeee 100644 --- a/src/electron/mpris.js +++ b/src/electron/mpris.js @@ -44,6 +44,11 @@ export function createMpris(window) { ipcMain.on('playerCurrentTrackTime', (e, position) => { player.getPosition = () => position * 1000 * 1000; + player.seeked(position * 1000 * 1000); + }); + + ipcMain.on('seeked', (e, position) => { + player.seeked(position * 1000 * 1000); }); ipcMain.on('switchRepeatMode', (e, mode) => { diff --git a/src/utils/Player.js b/src/utils/Player.js index 38c9aa1..db9b8d2 100644 --- a/src/utils/Player.js +++ b/src/utils/Player.js @@ -199,6 +199,9 @@ export default class { set progress(value) { if (this._howler) { this._howler.seek(value); + if (isCreateMpris) { + ipcRenderer?.send('seeked', this._howler.seek()); + } } } get isCurrentTrackLiked() { @@ -836,11 +839,14 @@ export default class { this.play(); } } - seek(time = null) { + seek(time = null, sendMpris = true) { + if (isCreateMpris && sendMpris && time) { + ipcRenderer?.send('seeked', time); + } if (time !== null) { this._howler?.seek(time); if (this._playing) - this._playDiscordPresence(this._currentTrack, this.seek()); + this._playDiscordPresence(this._currentTrack, this.seek(null, false)); } return this._howler === null ? 0 : this._howler.seek(); } diff --git a/src/views/lyrics.vue b/src/views/lyrics.vue index 40acc7f..a46695c 100644 --- a/src/views/lyrics.vue +++ b/src/views/lyrics.vue @@ -566,7 +566,7 @@ export default { }, setLyricsInterval() { this.lyricsInterval = setInterval(() => { - const progress = this.player.seek() ?? 0; + const progress = this.player.seek(null, false) ?? 0; let oldHighlightLyricIndex = this.highlightLyricIndex; this.highlightLyricIndex = this.lyric.findIndex((l, index) => { const nextLyric = this.lyric[index + 1];