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
share|improve this question

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

share|improve this answer

Install xbindkeys.

$ sudo apt-get install xbindkeys

Create the default configuration file for xbindkeys.

$ xbindkeys --defaults > ~/.xbindkeysrc

Edit the configuration file for xbindkeys.

$ nano ~/.xbindkeysrc

Add these lines:

"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
XF86AudioPlay <-- or the key(s) you want

"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop"
XF86AudioStop <-- or the key(s) you want

other examples of key binding:

# spotify controls
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
  F8 <-- key assigned

"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next"
  F9 <-- key assigned

Run xbindkeys to see if it all works:

$ xbindkeys

Now, when Spotify is running, pressing the play/pause key will make your music start or stop.

You will need to set xbindkeys to run automatically on startup. On Ubuntu, System -> Preferences -> Startup Applications.

Done!

sources: https://shkspr.mobi/blog/2011/12/linux-spotify-keybindings/ https://gist.github.com/jbonney/5743509#file-spotify_keybindings-L1

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.