Friday, May 28, 2010

Turn your Media PC into a SqueezeBox audio streamer

I'm a big fan of SlimDevices' (now Logitech) Squeezebox products.  See an overview of my whole house audio system.  As I now use my Media PC in my main audio listening area, I wanted to replace my older squeezebox classic with the same functionality on my Media PC.  While I love squeezebox products, I like even better that there is one less box in my TV stand.  +1 for my Media PC v.s. device clutter.

Fortunately, this is pretty easy to do and it works great.

If you already use Squeezeboxes, all you need is some software running on your Media PC called SqueezeSlave.  Download it and extract it into a folder on your Media PC.  SqueezeSlave is essentially a software version of a Squeezebox and connects to your SqueezeCenter audio server just like any other Squeezebox product.

Setting up Squeezeslave is pretty simple, I'll go through the steps so you can have it too.

Step #1:  Select your audio output

Media PCs have multiple audio output options.  This makes them extremely flexible for a variety of applications.  Why would you want to use multiple outputs?

Well, in my case I want to listen (and control) music without having my TV on.  Since my media PC drives my TV through a single HDMI connection, when my TV is off you can guess what happens to the sound.  Therefore, when listening to music, I need to use a different audio output.  With my Media PC I have several choices.  Here is a quick view of the back:
For me, the digital optical audio output is really convenient.  My receiver has an optical in and I only need to select that input when listening to music.

If I wanted, I could use a Coax (non-optical) S/PDIF instead, however with my motherboard I'd need an optional bracket to do this.  Here is an example of one SPDIF RCA Out Plate Cable Bracket.

NOTE:  SqueezeSlave (unlike the other software Squeezebox emulators), supports using alternate audio output devices.  This is very important otherwise we could just use SoftSqueeze or SqueezePlay.  These other players default to using the "current" audio device (which in my case would be my HDMI).

To force SqueezeSlave to use a specific audio out, you need to find out how it "numbers" the audio devices.  All you need to do is run squeezeslave with the -L option in a command window:

So, in my case, I want to select output "2".  Remember this value.

Step #2:  Create a simple batch file to run SqueezeSlave

You can run SqueezeSlave by itself as a command.  However, since SqueezeSlave takes some arguments you might want a batch file to make things easier.  Here is my batch file (copy it and save it as sqslave.bat).  Watch out for the long squeezeslave line, it wraps around.

@echo off
echo "Launching SqueezeSlave"
"C:\PATH_TO_SQUEEZESLAVE\squeezeslave-wasapi-0.9-184.exe" -o0 -D -m00:00:00:00:00:ff --retry IP_OR_HOSTNAME_OF_SERVER
echo "Warning: SqueezeSlave exited..."
echo "Sleeping for 10 seconds"
rem sleep 10
ping -n 11 >NUL
goto start

The batch file is pretty simple, but you will need to edit a few things:
  1. Change the -oN to the device that you want, listed by the -L command previously.  NOTE:  Be sure to use the same binary when you run -L and when you run the server for real.  The numbering for the output devices may be different between regular, ASIO, and WASAPI.  I made that mistake!
  2. If you like, change the -mXX... option to whatever virtual MAC address you want to be assigned to your player.  This should be unique and unless you have multiple squeezeslave players, you won't need to change this.
  3. Be sure to update the script with the full path to your SqueezeSlave binary.  I use WASAPI, as it supposedly enables a lossless audio stream.  If you want to use the ASIO version (also for lossless streams) you will need a driver like ASIO4ALL installed.  I've also tried the default version of SqueezeSlave and it works fine too.
  4. Update the IP address or hostname of your squeezebox server.  This can be your Media PC itself, if that happens to be where your run your server.  In my case, I use a separate computer (my desktop).

The -D option enables a text interface that emulates a squeezebox display.  This is kind of nice and allows you to control SqueezeSlave with simple keyboard commands (see below).  This is optional, of course.

The --retry option and batch file loop insures that if there is a problem, SqueezeSlave will keep trying or restart.  I've found this handy (see below).

If you do want to mess with WASAPI, make sure that your audio device supports exclusive mode and the 44.1Khz sample rate (or else you will get an error).  You can check this under Audio Properties in Windows 7 as shown below:

Step #3:  Automatically start Squeezeslave on boot

Unfortunately, Sqeezeslave is just a program without any wrapper to run it as a service.  What we need is something to make sure it is running every time the Media PC boots.  This is easy to do and another great reason to use EventGhost (see my post on EventGhost).

All you need to do is add an "action" to the AutoStart folder in EventGhost which launches the batchfile above.  This should run when EventGhost (and your computer) restarts:

Note:  If you exit EventGhost for some reason and restart it (sadly easy to do), you will get two SqueezeSlaves running.  Obviously this is bad, and you will notice right away that your music will stream for only a few seconds and restart.  Just kill the extra SqueezeSlave and things should resume normally.  No harm done.

Here is what the command window looks like when running SqueezeSlave:

Not very exciting, huh?  Well, since the TV will be off, having a bare bones UI is perfect.  However, even this simple UI is useful.

When the window has focus, you can use the keyboard to control SqueezeSlave.  Try pressing the spacebar to start/stop the music, arrows to navigate, +/- for volume, etc..  Run "SqueezeSlave --help" to see the full list of keys supported.

If you use the same remote setup as I do, you can program a button to raise the SqueezeSlave window.  Then the play/pause buttons on the remote will work!  This is handy for when the phone rings and you need to put the music on hold for a minute.

Step #4:  What if things go wrong?

Early versions of SqueezeSlave would often crash on me.  This doesn't seem to be a problem anymore thankfully.

However, I wrote a little batch file to automatically kill SqueezeSlave.  Since the batch file would restart it, I only had to wait 10 seconds for the SqueezeSlave to start up again.   To make this easy to restart, I even bound the batch file to the "Clear" button my remote using EventGhost.  All I needed to do is press this button when it got stuck.  Here is the batch file in case anyone finds this useful:

@echo off
echo "Killing SqueezeSlave"
taskkill /f /im squeezeslave*

Step #5:  Sit back and enjoy the music!

Finally, here is a quick video showing me controlling SqueezeSlave on my Media PC through a web interface.  I'm doing this with the TV on, but obviously I can do this from anywhere in the house, or with my iPhone.

BTW:  I'm currently enjoying Johnny Cash's Unearthed (5CD) as I write this - truly timeless music)


  1. Nice writeup! Thanks for posting this.

  2. A couple of questions please:

    1) To make sure the Squeezeslave application starts each time the PC boots: Could you just put a shortcut to the Squeezeslave application, in the Windows 'Startup' folder?

    2) I like the -D option you mention, that gives a text interface resembling a Squeezebox display. Although - is there any way at all, to allow the remote controls for the SB3/Transporter/etc control the text interface shown on the TV, along with (of course) controlling the audio output from the PC? If so, then you would essentially have the PC acting exactly as a Squeezebox, with no need at all to use another computer/laptop/etc as a virtual remote control...

  3. Dear Anonymous w/2 questions:

    1) Shortcuts in Windows don't take arguments (as far as I know). So, making a shortcut directly to the application wouldn't be very useful. However, you can do a shortcut to the batch file and that would accomplish the same thing as using EventGhost's Autostart action (in this case).

    2) I'm not sure I understand the question. If you mean: could you use an actual squeezebox remote? Yes, you could. You would need an IR receiver and software like EventGhost. See my post on programming my IR remote control. The type of remote (within reason) really doesn't matter.

    You would be limited to only the features supported by the -D interface, but that still would provide you with quite a few functions.

    The only downside is that you need to have the TV on to see most of the functions working (e.g. navigation of the text menu). However, the basics (pause, play, skip, volume) should work just fine without a display.

    Lots of choices in how you can control this!

  4. I just found this write-up, but thought I should add my $0.02:
    1) I use the Duet controller to control SqueezeSlave (in fact, I have 4 set up around the house, plus the duet receiver) - so this works even with the TV off.
    2) I set up SqueezeSlave as a service using srvany (part of the WinNT tool kit, IIRC).
    3) I use EventGhost to assign a key to restart Squeezeslave in case of trouble (restart the service).
    4) My own (tiny) contribution to SqueezeSlave was a "-H" command-line switch, to make it run in high priority. I use it to help ensure that the it has enough resources to prevent drop-outs.


Copyright (c) 2010 All Rights Reserved.