MPRIS – How to Prevent MPRIS from Recognizing an Application

audio playermprisshortcut-keys

I often have my audio player (usually Audacious v. 3.9) running while the Chrome browser is also running. If I open a video in Chrome, it seems to "claim" MPRIS controls from the audio player. The only way to get my shortcut keys to control Audacious is to close Chrome.

There must be a way of preventing MPRIS from recognizing Chrome as a "media player". I assume the problem is that one (or both) of these apps is not "claiming" MPRIS functions properly. According to the man page, this relates to an MPRIS_REMOTE_PLAYER variable:

MPRIS_REMOTE_PLAYER
If unset or set to *, mpris-remote will communicate with the first player it finds registered under "org.mpris.*" through D-BUS. If you only have one MPRIS-compliant player running, then this will be fine. If you have more than one running, you will want to set this variable to the name of the player you want to connect to. For example, if set to foo, it will try to communicate with the player at "org.mpris.foo" and will fail if nothing exists at that name.

My problem is that I don't know how to set this variable. I've looked in the D-bus editor for something corresponding to this (on the analogy in an answer about media-players in the tray), but there is no relevant setting there that I can spot.

Meanwhile, I have discovered this:

$ qdbus org.mpris.*
org.mpris.MediaPlayer2.audacious
org.mpris.MediaPlayer2.chrome.instance13448

So it seems Audacious does have its "own" MPRIS identity, so how can I prevent Chrome from being recognized as a "media player" for MPRIS purposes? Any help with setting that up would be greatly appreciated.

P.s. I'm on Ubuntu 18.04 LTS.

Best Answer

While it would still be good to know if there is an "MPRIS-managed" solution to this problem, there is a work-around using the settings in Chrome itself.

It seems Chrome is quite aggressive in "taking over" control of media keys/shortcuts. This can be disabled by following these steps, found in a post on the GHacks.net site:

You may disable the Hardware Media Key Handling flag in Chrome currently to prevent Google Chrome from restricting media keys access. Here is how that is done:

  1. Load chrome://flags/#hardware-media-key-handling in the Chrome address bar; this should open the right flag when loaded.
  2. Set the Hardware Media Key Handling flag to Disabled.
  3. Restart Google Chrome.

When I set this toggle on my machine, Chrome offered a "Relaunch" button which restarted the browser with the tabs from the previous/re-started session intact.

This takes care of my issue—with the caveat that if there is an MPRIS "solution" (i.e., use the MPRIS spec to "hide" a potential media-player), I would still like to know. ;)

Related Question