feat(player): sync playing progress to mpris service on linux

Co-authored-by: alex3236 <45303195+alex3236@users.noreply.github.com>
This commit is contained in:
Revincx 2023-08-26 09:03:36 +08:00
parent 6ad756b215
commit 486b04b70b
No known key found for this signature in database
GPG Key ID: 6E79B88F79CA3126
3 changed files with 14 additions and 3 deletions

View File

@ -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) => {

View File

@ -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();
}

View File

@ -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];