7

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.

2 Answers 2

10

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. ;)

3
  • 2
    perfect! this is exactly what fixed it for me as well. thank you! Dec 31, 2019 at 18:29
  • 1
    This chrome flag has been removed in Chrome 101. Please star bugs.chromium.org/p/chromium/issues/detail?id=1321112 if you run into this. Apr 29, 2022 at 13:39
  • 1
    For Firefox, launch this in URL: about:config then set media.hardwaremediakeys.enabled in search bar, click disable.
    – poka
    May 7, 2023 at 11:42
3

I have just "discovered" Playerctl (or, on Github). playerctl is a wonderful command line tool that solves some (all?) of OP's problems. From the official "About":

Playerctl is a command-line utility and library for controlling media players that implement the MPRIS D-Bus Interface Specification. Playerctl makes it easy to bind player actions, such as play and pause, to media keys. You can also get metadata about the playing track such as the artist and title for integration into statusline generators or other command-line tools.

For more advanced users, Playerctl provides an introspectable library available in your favorite scripting language that allows more detailed control like the ability to subscribe to media player events or get metadata such as artist and title for the playing track.

It is a very simple way of using MPRIS controls while targetting particular media players, among much else besides. It can be used to address directly OP's main concern in this way:

  1. Install playerctl, easy from the .deb
  2. Identify the player you wish to control. This can be done either as OP did, from the distinct terminating element in the responses to $ qdbus org.mpris.*, or (using playerctl itself), with $ playerctl --list-all.
  3. You can then target the controls you wish to use with that player's name, e.g.: $ playerctl --player=audacious play-pause (which toggles play/pause). Now, no other MPRIS related player can "steal" that instruction.
  4. Assign that command to a shortcut key (Preferences > Devices > Keyboard > +).

It thus becomes a simple matter to target MPRIS instructions that will not get "taken over" by some other player/app, which is OP's triggering concern.

A full set of instructions is available at Playerctl's github readme.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .