Monday, November 15, 2010

Streaming music from Squeezebox Server to an iOS device

A few years ago, I noticed that it was not possible to stream music from Squeezebox Server (previously called SlimServer, then SqueezeCenter) to an iPod Touch. Fortunately, things have changed: bugs have been fixed and iOS 4 now supports multitasking (since June 2010). A few weeks ago, I reinstalled Squeezebox Server on my Ubuntu server and realized that it was finally possible to use my iPhone to play music from my server. Here’s how I currently do it:
  1. Start Safari on your iPhone
  2. Enter the following URL: http://myserver:9000/stream.mp3 (or http://user:password@myserver:9000/stream.mp3, but this is less secure and will cause Safari to display a warning message)
  3. Start iPeng (a remote control application for Squeezebox Server) or any other equivalent application
  4. Add tracks to the player matching your iPhone and play them
I don’t know if it’s the optimal way to do it or not, so any hints or suggestions will be appreciated. In my experience, the main drawback of this method is that Safari buffers a lot of audio before playing it, so expect a long delay (15-30 seconds) when playing a new track. Also, you won’t be able to use Safari to access any other sites. I guess a dedicated streaming client (instead of Safari Mobile) could help, but I don’t know if such an application even exists.

Update (November 27, 2010). There's a streaming client called OPlayer Lite that, according to my experience, buffers about half as much audio as Safari Mobile. I've also just discovered another application called Squeezecast, but it's not free (it's $5.99, which sounds expensive as it apparently still requires iPeng to manage the playlists). Does anybody have any experience with it?

Another "trick" that I'm now using is to connect from my iPhone using the following URL:

http://user:password@myserver:9000/stream.mp3?name=Olivier%27s+iPhone&bitrate=160

The "bitrate" parameter in the URL forces the bitrate to the specified value if the player doesn't exist yet (so you don't have to change it in the settings). The "name" parameter is the name of the player to use or create. That way, your iPhone won't create a new player every time your IP address changes. Unfortunately, that feature is still not supported in Squeezebox Server. There's a feature request for that on bugs.slimdevices.com that has been open since 2005! The good news is that it's pretty straightfoward to patch Squeezebox Server. In the processURL function in Slim/Web/HTTP.pm, add the following lines:

if ($params->{'name'}) {
  $address = $params->{'name'};
  main::INFOLOG && $log->is_info && $log->info("processURL using address=$address");

}

just before:

$client = Slim::Player::Client::getClient($address);


and the following lines:

if ($params->{'name'}) {
  $client->name($params->{'name'});

}

just after:

if ( $params->{userAgent} ) {
  ...
  $client->name( $agent . ' ' . string('FROM') . ' ' . $address );

}

Update (February 9, 2011). iPeng now supports playback (i.e. it can act as a Squeezbox player without any third-party application). The feature is not free (it is available as an in app purchase), but, according to my tests, it is well worth the price ($4.99).

4 comments:

Anurag said...

Have you tried this app to try and stream from your squeezebox server?

http://www.edavs.com/OPlayer.shtml

Olivier Bruchez said...

Thanks for the suggestion! I've tried OPlayer Lite. A quick test shows that it buffers about half as much music before playing it than Safari Mobile. That's 2-3 times more than iTunes on Mac OS X, for example (on the same internet connection, of course), but, still, it's a step in the right direction. A would buy such an app if it had low latency and/or more settings for the way the audio is buffered.

Unknown said...

I use this modification as well. I have found with the current version of Logitech Media Server, I have to make two additional changes.

Just after
sub processURL {

Add
my $address = "";

Change the line
my $address = $params->{player} || $peeraddr{$httpClient};

To
$address = $params->{player} || $peeraddr{$httpClient};

Anonymous said...

To be clear on the point...
"iPeng now supports playback (i.e. it can act as a Squeezbox player without any third-party application). The feature is not free (it is available as an in app purchase), but, according to my tests, it is well worth the price ($4.99)."

Ipeng currently runs $9.99 (1/2013), but to enable the on-ipad playback feature runs another $4.99. I missed that distinction and just bought iPeng (#S) thinking both features were bundled. I don't need iPeng's core multi-head management or syncing features, I just want to listen to my server music via my ipad while my son watches TV on the prime speakers.
I'm probably going to make do with the variety of other players available to do normal "stream.mp3" streaming and do control via the media server http webui for free.

Thanks for the tips and useful info, though.