-
Notifications
You must be signed in to change notification settings - Fork 557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Invalid mpris position report #2225
Comments
I'm seeing this issue still in v3.4.1 |
I've been having this issue for a while, here's more information about it:
I could not bisect it properly because there were some broken commits for me, but reverting eaf9d31 seems to fix it. Here's a demonstration video of the issue (and the workaround): mpris_position.mp4(In the video you can see the position does not update when playing the song, it stays at around the same timestamp) Edit: I figured it out The issue happens because this callback isn't called (reloading the page triggers this event, which runs the callback and fixes the issue) youtube-music/src/plugins/shortcuts/mpris.ts Lines 121 to 130 in 32a572b
That event used to be sent AFTER registerMPRIS(), so the callback runs. However, after commit eaf9d31 that event is sent BEFORE registerMPRIS(), i.e. before the listener is created. youtube-music/src/plugins/shortcuts/main.ts Lines 51 to 53 in eaf9d31
Anyway, here's a possible solution (I'm not opening a PR, because the bad commit was already reverted 7599cc6 ) diff --git a/src/plugins/shortcuts/main.ts b/src/plugins/shortcuts/main.ts
index 84c29899..59f40d13 100644
--- a/src/plugins/shortcuts/main.ts
+++ b/src/plugins/shortcuts/main.ts
@@ -48,9 +48,10 @@ export const onMainLoad = async ({
_registerLocalShortcut(window, 'CommandOrControl+L', search);
if (is.linux()) {
- ipcMain.once('ytmd:video-src-changed', (_) => {
- registerMPRIS(window);
- });
+ const channels = ['ytmd:player-api-loaded','ytmd:video-src-changed']
+ .map((channel) => new Promise((resolve) => ipcMain.once(channel, resolve)));
+
+ Promise.all(channels).then(() => registerMPRIS(window));
}
const { global, local } = config;
diff --git a/src/plugins/shortcuts/mpris.ts b/src/plugins/shortcuts/mpris.ts
index cdfc9d4b..59b269b4 100644
--- a/src/plugins/shortcuts/mpris.ts
+++ b/src/plugins/shortcuts/mpris.ts
@@ -118,7 +118,7 @@ function registerMPRIS(win: BrowserWindow) {
player.setPosition(player.getPosition() + offset);
};
- ipcMain.on('ytmd:player-api-loaded', () => {
+ const onApiLoaded = () => {
win.webContents.send('ytmd:setup-seeked-listener', 'mpris');
win.webContents.send('ytmd:setup-time-changed-listener', 'mpris');
win.webContents.send('ytmd:setup-repeat-changed-listener', 'mpris');
@@ -127,7 +127,10 @@ function registerMPRIS(win: BrowserWindow) {
win.webContents.send('ytmd:setup-autoplay-changed-listener', 'mpris');
requestFullscreenInformation();
requestQueueInformation();
- });
+ };
+
+ onApiLoaded();
+ ipcMain.on('ytmd:player-api-loaded', onApiLoaded);
ipcMain.on('ytmd:seeked', (_, t: number) => {
player.setPosition(secToMicro(t)); |
Preflight Checklist
YouTube Music (Application) Version
3.3.12
Checklists
What operating system are you using?
Other Linux
Operating System Version
Linux fuhen 6.6.36 #1-NixOS SMP PREEMPT_DYNAMIC Thu Jun 27 11:49:15 UTC 2024 x86_64 GNU/Linux
What CPU architecture are you using?
x64
Last Known Working YouTube Music (Application) version
/shrug
Reproduction steps
playerctl position
and see something like0.0025
playerctl position
and see the position you seeked to (so 60.567 for example)playerctl position
and see the same value (or close to) as before (so 60.4567 instead of 65.12 for example)Expected Behavior
Mpris's position should be reported correctly, even when not seeking manually
Actual Behavior
See reproduction steps.
Enabled plugins
[YTMusic] Plugin "shortcuts::menu" loaded
[YTMusic] Plugin "lyrics-genius::menu" loaded
[YTMusic] Plugin "downloader::menu" loaded
[YTMusic] Plugin "album-color-theme::menu" loaded
[YTMusic] Plugin "shortcuts::menu" loaded
[YTMusic] Plugin "lyrics-genius::menu" loaded
[YTMusic] Plugin "downloader::menu" loaded
[YTMusic] Plugin "album-color-theme::menu" loaded
Additional Information
No response
The text was updated successfully, but these errors were encountered: