14

I'm using Ubuntu with Gnome. My multimedia keys (play/pause, stop, etc) were working fine and then all of a sudden they stopped working.

In particular I'd like for them to work with Spotify.

bmaupin
  • 4,930

1 Answers1

29

Common solutions

If the multimedia keys were already working but stopped working, one or more of these solutions may help:

  • Restart gsd-media-keys (see Troubleshooting below to see why this may be necessary)

    • Ubuntu 20.04+

      systemctl --user restart gsd-media-keys.target
      
    • Previous versions

      killall gsd-media-keys
      
  • Try closing all applications, then open the one you want to receive the multimedia keys first

    • Applications that receive multimedia keys may take all keypresses and prevent other applications from receiving them
    • Common applications which receive multimedia keys:
      • Chrome
      • Firefox
      • Spotify
      • Other Electron-based applications may grab multimedia keys if you start playing a media file (e.g. Microsoft Teams)
  • Another workaround is to completely disable multimedia key support for certain applications

    • Chrome

      1. In the address bar go to chrome://flags/#hardware-media-key-handling
      2. Change the value to Disabled
      3. Restart Chrome
    • Firefox

      1. In the address bar go to about:config
      2. If necessary, click Accept the Risk and Continue
      3. Search for media.hardwaremediakeys.enabled
      4. Set it to false by clicking the toggle button
      5. Restart Firefox
    • Microsoft Teams

      There's no setting in the application to disable media keys, but you can use this workaround since it's an Electron app:

      1. Copy the default desktop file

        cp /usr/share/applications/teams.desktop ~/.local/share/applications/teams.desktop
        
      2. Add a parameter to disable the media keys

        sed -i 's/^Exec=teams %U/Exec=teams --disable-features=HardwareMediaKeyHandling %U/' ~/.local/share/applications/teams.desktop
        

      If you've configured Teams to automatically start, you can use these steps:

      1. Disable autostart from within Teams (3 dots menu > Settings > uncheck Auto-start application)

      2. Create a custom autostart file

        cp /usr/share/applications/teams.desktop ~/.config/autostart/teams-custom.desktop
        
      3. Add a parameter to disable the media keys

        sed -i 's/^Exec=teams %U/Exec=teams --disable-features=HardwareMediaKeyHandling %U/' ~/.config/autostart/teams-custom.desktop
        
  • Reset media key shortcuts to their default values

    dconf reset /org/gnome/settings-daemon/plugins/media-keys/next
    dconf reset /org/gnome/settings-daemon/plugins/media-keys/pause
    dconf reset /org/gnome/settings-daemon/plugins/media-keys/play
    dconf reset /org/gnome/settings-daemon/plugins/media-keys/previous
    
  • For even more control, see Playerctl


Troubleshooting

  1. Use dbus-send to list the applications which are configured via MPRIS to receive multimedia keys, e.g.:

    $ dbus-send --print-reply --dest=org.freedesktop.DBus  /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep org.mpris
      string "org.mpris.MediaPlayer2.spotify"
      string "org.mpris.MediaPlayer2.chrome.instance22348"
    

    In this example, you can see Spotify and Chrome (org.mpris.MediaPlayer2.chrome.instance22348) are configured to receive the multimedia keys

    • Note: If you see an entry like org.mpris.MediaPlayer2.chromium.instance16163 but you don't have Chromium installed, it may be for an Electron-based application.
  2. Watch /var/log/syslog

    tail -F /var/log/syslog
    
  3. Press a media key (play, pause, stop, etc)

  4. Look in the log for any pertinent messages, e.g.

    Mar 26 12:23:17 hostname gsd-media-keys[1762]: Error calling method GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.mpris.MediaPlayer2.chrome.instance10062 was not provided by any .service files
    

    In this example, you can see that the key is being sent to org.mpris.MediaPlayer2.chrome.instance10062 even though that application isn't in the list in step 1.

    The solution (above) is to restart gsd-media-keys.

  5. If none of the above helped, make sure the media key shortcuts are all set to their default values

    dconf read /org/gnome/settings-daemon/plugins/media-keys/next
    dconf read /org/gnome/settings-daemon/plugins/media-keys/pause
    dconf read /org/gnome/settings-daemon/plugins/media-keys/play
    dconf read /org/gnome/settings-daemon/plugins/media-keys/previous
    

    If the keys are all set to their default values, no output should be returned, e.g.:

    $ dconf read /org/gnome/settings-daemon/plugins/media-keys/next
    $ dconf read /org/gnome/settings-daemon/plugins/media-keys/pause
    $ dconf read /org/gnome/settings-daemon/plugins/media-keys/play
    $ dconf read /org/gnome/settings-daemon/plugins/media-keys/previous
    $
    
bmaupin
  • 4,930
  • 5
    My problem was related to google chrome. It was capturing media keys and the flag set to disabled worked, thanks ! – Baptiste Apr 02 '20 at 13:25
  • I use play/pause media key when using Banshee. When I view a YouTube video in Chrome, it takes over the key use, even if Ive closed Chrome. This does not happen with Firefox. Thanks for this solution, Im creating a bash function so I can quickly restore my media keys when this happens, and be less distracted at work! – Todd Sep 11 '20 at 14:28
  • 2
    +1, Chrome was intercepting my keys too. By disabling the chrome flag it worked! Thanks! – Evan Nov 16 '21 at 00:41
  • 2
    Nice - thank you for the detailed troubleshooting steps and various fixes! – Mark McDonald Jan 24 '22 at 02:36
  • 1
    Amazing write up! Disabling chrome flag worked here as well. Guessing that will be the most common problem for when keys "used to work". Would love an app or Gnome extension that could indicate which app is to be used with media keys. Not sure if that would work, since it looks like apps are able to request/hijack media keys on start up. – swapsCAPS Jan 31 '22 at 10:34
  • @swapsCAPS There might be a way; it would probably be worth asking as a separate question. I'm not sure if playerctl could do what you're asking. But if you know you want a specific key to always work for only one application, you can use dbus-send to send the key to only that application. – bmaupin Jan 31 '22 at 13:11