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.
1 Answer
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.targetPrevious 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
- In the address bar go to
chrome://flags/#hardware-media-key-handling - Change the value to
Disabled - Restart Chrome
- In the address bar go to
Firefox
- In the address bar go to
about:config - If necessary, click Accept the Risk and Continue
- Search for
media.hardwaremediakeys.enabled - Set it to
falseby clicking the toggle button - Restart Firefox
- In the address bar go to
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:
Copy the default desktop file
cp /usr/share/applications/teams.desktop ~/.local/share/applications/teams.desktopAdd 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:
Disable autostart from within Teams (3 dots menu > Settings > uncheck Auto-start application)
Create a custom autostart file
cp /usr/share/applications/teams.desktop ~/.config/autostart/teams-custom.desktopAdd 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/previousFor even more control, see Playerctl
Troubleshooting
Use
dbus-sendto 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.instance16163but you don't have Chromium installed, it may be for an Electron-based application.
- Note: If you see an entry like
Watch /var/log/syslog
tail -F /var/log/syslogPress a media key (play, pause, stop, etc)
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 filesIn this example, you can see that the key is being sent to
org.mpris.MediaPlayer2.chrome.instance10062even though that application isn't in the list in step 1.The solution (above) is to restart
gsd-media-keys.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/previousIf 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 $