mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-16 05:08:04 +00: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
3 changed files with 14 additions and 3 deletions
|
|
@ -44,6 +44,11 @@ export function createMpris(window) {
|
||||||
|
|
||||||
ipcMain.on('playerCurrentTrackTime', (e, position) => {
|
ipcMain.on('playerCurrentTrackTime', (e, position) => {
|
||||||
player.getPosition = () => position * 1000 * 1000;
|
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) => {
|
ipcMain.on('switchRepeatMode', (e, mode) => {
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,9 @@ export default class {
|
||||||
set progress(value) {
|
set progress(value) {
|
||||||
if (this._howler) {
|
if (this._howler) {
|
||||||
this._howler.seek(value);
|
this._howler.seek(value);
|
||||||
|
if (isCreateMpris) {
|
||||||
|
ipcRenderer?.send('seeked', this._howler.seek());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
get isCurrentTrackLiked() {
|
get isCurrentTrackLiked() {
|
||||||
|
|
@ -836,11 +839,14 @@ export default class {
|
||||||
this.play();
|
this.play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
seek(time = null) {
|
seek(time = null, sendMpris = true) {
|
||||||
|
if (isCreateMpris && sendMpris && time) {
|
||||||
|
ipcRenderer?.send('seeked', time);
|
||||||
|
}
|
||||||
if (time !== null) {
|
if (time !== null) {
|
||||||
this._howler?.seek(time);
|
this._howler?.seek(time);
|
||||||
if (this._playing)
|
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();
|
return this._howler === null ? 0 : this._howler.seek();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -566,7 +566,7 @@ export default {
|
||||||
},
|
},
|
||||||
setLyricsInterval() {
|
setLyricsInterval() {
|
||||||
this.lyricsInterval = setInterval(() => {
|
this.lyricsInterval = setInterval(() => {
|
||||||
const progress = this.player.seek() ?? 0;
|
const progress = this.player.seek(null, false) ?? 0;
|
||||||
let oldHighlightLyricIndex = this.highlightLyricIndex;
|
let oldHighlightLyricIndex = this.highlightLyricIndex;
|
||||||
this.highlightLyricIndex = this.lyric.findIndex((l, index) => {
|
this.highlightLyricIndex = this.lyric.findIndex((l, index) => {
|
||||||
const nextLyric = this.lyric[index + 1];
|
const nextLyric = this.lyric[index + 1];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue