Skip to content
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

Add support for media keys using mpris2 on the linux platform #65

Closed
jrabinow opened this issue Nov 26, 2020 · 12 comments
Closed

Add support for media keys using mpris2 on the linux platform #65

jrabinow opened this issue Nov 26, 2020 · 12 comments
Labels
enhancement New feature or request

Comments

@jrabinow
Copy link

This app is perfect in every way ❤️ , except for one thing: currently, media keys don't seem to work on my setup (linux).

Would it be possible to add support for the mpris2 protocol? You can find a working implementation here
and the full spec is here in case you needed to refer to it

@th-ch th-ch added the enhancement New feature or request label Nov 27, 2020
@azizLIGHT
Copy link

azizLIGHT commented Nov 28, 2020

There is some kind of mpris implementation because it works for me on Manjaro on Gnome. I can press pause/play/prev/next successfully and it carries over to my bluetooth headset buttons too. Maybe its not to spec like you say as some things are working for some and not others? In any case, here's what I noticed related to mpris:

When i query qdbus for track information by mpris, the app name is a random chromium instance number like org.mpris.MediaPlayer2.chromium.instance1820402 instead of something like org.mpris.MediaPlayer2.youtube-music. I also can't query full track information with qdbus org.mpris.MediaPlayer2.chromium.instance1820402 org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Metadata like you would for a player like vlc, I get nothing returned back on the prompt. A Gnome extension I use to display now-playing information in my top panel can find track information, but the Artist has - Topic appended at the end of it and Title seems cutoff
image.

The notifications show proper track information however:
image

Hope this info helps implementing the mpris spec fully!

@jrabinow
Copy link
Author

jrabinow commented Nov 28, 2020

@azizLIGHT I can only guess why it's working for you but not for me: since you mention you're using Gnome, would it be possible for Gnome to be using its own media keys solution independent of mpris? Maybe even something similar to this

On my end, my DE has no such media key service built in. I'm using a keyboard shortcut tied to https://github.com/mackstann/mpris-remote (actually I updated the code a fair bit, long story short it works with mpris2. Tested and confirmed all players work except this one). Per my understanding, the way dbus works internally is it looks for any mpris-compatible players that registered themselves and dispatches them the message - so my guess is the name of the app doesn't matter, it's just that there's no mpris support at the moment, or that it didn't register.

Would there be a way for you to confirm that the media keys are actually working through mpris on your setup? Possibly dbus-monitor would be of help https://wiki.ubuntu.com/DebuggingDBus I'm not sure it'll display when apps receive a sent message but it's worth a shot IMO

EDIT: I have to say I'm quite mystified by your gnome plugin which doesn't seem to be using anything other than mpris (or maybe I'm missing something, I spent all of 10min looking through the source) - though I'm still rather confident that mpris isn't supported by youtube-music app since grepping the source for mpris didn't reveal a single result

@th-ch
Copy link
Owner

th-ch commented Dec 2, 2020

Hey @jrabinow & @azizLIGHT, thanks for the precise feedback! I have opened a draft PR #78 but I have no setup to test it 😬
Feel free to test it out and update the issue accordingly! To run it, you need node.js and yarn, then:

git clone https://github.com/th-ch/youtube-music
cd youtube-music
git checkout mpris
yarn
yarn start

@jrabinow
Copy link
Author

jrabinow commented Dec 3, 2020

Hey @th-ch thanks so much! I'm afraid there's a bug somewhere, attached are the tracebacks:

dbus-monitor-out.txt
mpris-remote-cmd-out.txt

I'm not sure if you have a linux distro available to test things out on, if you do you can check out playerctl or mpris-remote... otherwise I'll do my best to test things out whenever I get the chance

@JoeJoeTV
Copy link

JoeJoeTV commented Jul 6, 2021

Are there any updates to this? I could maybe test it on my Linux Mint install, if that helps.

@itzmanish
Copy link
Contributor

I have tested on Arch linux with playerctl. So please merge this.

@itzmanish
Copy link
Contributor

@th-ch when this will be release? I am waiting only for this because I don't know how do I install in arch linux. (PS- I am also lazy to go through tutorials)

@th-ch
Copy link
Owner

th-ch commented Sep 9, 2021

Hey @itzmanish, I still need to go through a few PRs (like #389) and then I'll release a new version, probably in the following weeks!

@itzmanish
Copy link
Contributor

@th-ch I created new PR #431 for this issue. Please check the PR for details.

@jrabinow
Copy link
Author

jrabinow commented Nov 9, 2021

I'm going to close this issue as all changes have shipped with the latest release. If people are still running into problems, please feel free to reopen.

Thanks everyone!

@jrabinow jrabinow closed this as completed Nov 9, 2021
@JoeJoeTV
Copy link

JoeJoeTV commented Nov 9, 2021

I'm still having issues with this after updating to the newest version(1.14.0).
The mpris2 control now properly shows YouTube Music with the song info(title and artist) and also the cover, but only the previous and next buttons work.
There is also still a "Chromium" control, that shows the song info without a cover art, but there, all buttons(previous, play/pause, stop and skip) work in contrast to the "correct" control.

EDIT: Also the progress bar doesn't work as in, it doesn't reflect the progress of the playing song and changing it in the mpris control interface doesn't seek to that part. The "Chromium" control doesn't even show a progress bar.

EDIT2: I have looked into this using d-feet and qdbusviewer and the Play() and Pause() methods work, but the PlayPause() and Stop() methods do not. Also the Position property stays at 0 and the Seek method does nothing, no matter, what the argument value is.

I'm on Linux Mint Cinnamon 20.2 64x and have installed the .deb version.

@Araxeus
Copy link
Collaborator

Araxeus commented Nov 9, 2021

@JoeJoeTV I have possible fixes in mind but no way to test on windows. would you be willing to help me test?

if so add me on discord Araxeus#0819

fix playPause:

	MPRISPlayer.on("playpause", playpause);

fix displayed time in mpris:

youtubePlayer.onTimeUpdate = time =>
    mprisPlayer.seeked(time)

seek from mpris progress bar:

player.on('seek', (offset) => {
   // note that offset may be negative
   const currentPosition = youtubePlayer.getPositionInMicroseconds();
   const newPosition = currentPosition + offset;
   realPlayer.setPosition(newPosition);
});

docs:
https://www.npmjs.com/package/mpris-service
https://github.com/dbusjs/mpris-service/blob/master/src/index.js#L26-L132
https://github.com/dbusjs/mpris-service/search?q=seeked
https://github.com/dbusjs/mpris-service/blob/master/examples/player.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants