Ubuntu – Windows play/pause keys on Xubuntu Spotify

shortcut-keysspotifyxubuntu

I have tried to find out how to set my media keys to work with Spotify on Xubuntu 14.04. I tried setting spotify as my default music player. I thought this would be a simple task, but I can't figure out a way to do this, and am not sure it will even work.

Here is the output for xev for my play/pause button (I don't know what any of this means but here you go:

    KeyPress event, serial 37, synthetic NO, window 0x4600001,
    root 0x497, subw 0x0, time 2164738, (756,-274), root:(1350,51),
    state 0x0, keycode 172 (keysym 0x1008ff14, XF86AudioPlay), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

    KeyRelease event, serial 37, synthetic NO, window 0x4600001,
    root 0x497, subw 0x0, time 2164823, (756,-274), root:(1350,51),
    state 0x0, keycode 172 (keysym 0x1008ff14, XF86AudioPlay), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

Best Answer

Xfce/Xubuntu actually already includes the functionality to map multimedia keys to custom commands, so this can be done without having to install any extra packages or create any files:

  1. Bind the keys
    (This can also be done manually through SettingsKeyboardApplication Shortcuts)

    xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/XF86AudioPlay -s "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause" -n -t string
    xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/XF86AudioNext -s "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next" -n -t string
    xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/XF86AudioPrev -s "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous" -n -t string
    
  2. Log out and log back in (alternatively you can close any apps that may be intercepting multimedia keys, in my instance this meant Google Chrome)

It worked for me on two different computers: A Dell Optiplex running Xubuntu 14.04 and a Thinkpad running Xubuntu 16.04.

I also added a few additional notes with more detailed troubleshooting, etc. here: https://gist.github.com/bmaupin/acc566ff44a8ebf20c2aa2707789e6ea

Related Question