Multimedia keys sometimes stop working

Solution 1:

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
    $