Technical stuff, mostly to remind myself when I forget in a couple of months' time.

Tuesday, 22 November 2011

Logitech Media Server and media keys

I use squeezeslave to listen to music from my Logitech Media Server (LMS; previously known as Squeezebox Server).  The LMS has a pretty good web UI which can be used to control the player.  However, it's quicker to be able to use the media keys to do simple actions - pause/resume, previous, next.  It saves having to navigate to the browser window and move the mouse around.

Here's how I set this up on Ubuntu 11.04.

Firstly, you need a script to send commands directly to the LMS command line interface (CLI).  Luckily someone has written this.  The script is called sccmd and it's part of the squeezeslave codebase, I think.  However, I couldn't figure out how to get it from the main squeezeslave page at sourceforge and in fact I originally found it on github where someone has a mirror of the code.  Just copy the script to somewhere appropriate on your local drive (I put it in ~/bin which is automatically on the path in Ubuntu), modify it as necessary for your player and server (change the MAC address and host name) and make it executable.

Secondly, you need to map the keys.  Disable the media keys in the Keyboard Shortcuts settings panel. Then, if you're using Unity, then you can map the keys to the script using the CompizConfig Settings Manager (compizconfig-settings-manager in the Universe repository).  Go to the "Commands" plugin (enabling it if necessary) and define three command lines.  They are:

  • /home/user/bin/sscmd pause
  • /home/user/bin/sscmd "button jump_rew"
  • /home/user/bin/sscmd "button jump_fwd"

Then go to the second tab, Key Bindings, and define the keys.  This is a simple matter of clicking the "Disabled" button, clicking "Grab key combination" and pressing the appropriate key.

Finally, if you are using this remotely over ssh (as per my previous post) then you need to modify the ssh config to forward port 9090, which is the port used by the CLI (or change it in the LMS settings to a different port and forward that).  In this case, the host name in the sccmd file will be "localhost".

Update: in 12.10 I found that I needed to install the package "compiz-plugins" to get the "Commands" plugin.

Your Host

Husband, father, pop music anorak, guitarist