mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2025-02-20 17:13:48 +08:00
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:
parent
6ad756b215
commit
486b04b70b
|
@ -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) => {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in New Issue
Block a user