How To Listen To BBC Internet Radio Streams On A Sonos

2008.03.24

6 comments

Welcome to my first and already updated how-to, How to listen to BBC Internet radio streams on a Sonos or any other MP3 streaming device.

Originally, it was called How to listen to BBC Internet radio streams outside the UK (on a Sonos or any other MP3 streaming device). James Cridland kindly left a comment pointing out that BBC Internet radio streams can be listened to worldwide. You're still welcome to read about the outdated (as it's only of “historical interest” now) preceding adventure, but you probably may want to jump straight to the new how-to.

Your mission, should you decide to accept it…

In early 2008 I've been kindly asked a favour to help someone in the family. Not the family, and not mine, either; rather of the one who asked me. To stay in bad movie references – it was something I couldn't refuse, as it also was challenging and interesting: Make it possible to (1) listen to BBC Internet radio streams (2) outside the UK (3) on a Sonos.

Analyzing the problem

Listen to BBC Internet radio streams…

Problem #1 wasn't too hard to solve. All you had to do was living in the UK! Why? It was per se not possible to listen to and view any of the BBC Internet streams if you lived outside the UK (a comprehensible decision since the BBC is funded by UK television licences).

Technically speaking, if your IP address was not traceable to be in the UK physically, you couldn't access their streaming services.

…outside the UK…

So what did you do if you didn't live in the UK? As the files are in the computer (I'm so sorry for those references) and don't require your physical presence, a computer could do the “living in the UK” for you. We could use this as a loophole, as we just needed an UK based computer to act as an intermediary.

Solution: rent a technically sufficient server in the UK that serves this purpose.

…on a Sonos

If your flat is big enough or you own a house, have an affinity to technology (as in “recent technology”) and music, you'd probably come across Sonos already. If not, read the Wikipedia article (it mentions alternatives, too, so I don't have to).

Technically, it's only of interest to know the file formats Sonos supports. The BBC Internet radio streams itself are provided in RealAudio (for the record, some are in Windows Media Audio, too).

A first shot

I really appreciate people reading and trying in advance before actually asking for help. In this case, I've not only had a hypothetical scenario presented – the server had been rented already, too. Way to go! Their scenario and ultimately renting the server nicely summed up and confirmed my analysis: get a middleman, talk to the middleman and request the stream, and finally, receive the stream.

For more details, the scenario proposed an “URI based proxy server”, as Sonos' do not provide the possibility of using a proxy server. An URI like http://[that rented server proxy]/[here goes the BBC Internet radio stream adress] should return the desired content.

That didn't work

The idea behind it was sustainable, the execution was not. It failed for two reasons: (1) Sonos' do not support RealAudio and (2) after using all-knowing Google I learned that RealAudio streaming contents just don't like being connected through a proxy server.

In technical details, RTSP (the protocol for streaming inter alia RealAudio and Windows Media Audio) and proxies is like camels and the eyes of needles. I don't want to say “bitch”, it's just I'd not even touch it with pincers.

A reevaluation (including a side evaluation)

I then tried figuring out a solution using VLC, a software player that not only can play almost any audio (and video), but stream it as well in almost any format, too. It should be the swiss army-knife go-between. Again, the idea was good, but the execution wasn't due to many dependencies. Simply put, controlling this beast in a decent way is like driving a racing car without ever having attended a driving school, and I know what I'm talking about.

More googling pointed me to the very own Sonos forum for a similar idea with a similar player called MPlayer. The concept was pretty much the same as with VLC: good idea, but not viable. Later, I should come across MPlayer again, but part of the solution that finally would work.

For the tech-savvy: one of the issues was traffic, as one of the ideas included running several instances of VLC or MPlayer that continuously pull the BBC streams. By then – shame on me – I hadn't thought of a decent web based control script to start and stop these players or to give them new URIs (not a convenient way if you want to use your Sonos exclusively to control the stations). Instead, I had ideas like running PortSentry that should look for corresponding port connections and performing actions depending on those.

Technical side evaluation

Also, but as soon discarded as suggested, I evaluated simply routing any RTSP traffic that the Sonos would demand through the UK server, but it was technically not feasible as this would require a manipulation of a capable router that didn't exist.

An idea that would work, sort of first, good in the end

Enter SqueezeCenter

More googling and and some tea later I stumbled upon SqueezeCenter. Simplified, it's the open source software version of Sonos (there's a hardware solution as well). It can use your digital music library as a source as well as almost any Internet audio stream to stream from to any device that supports MP3 streams. Sonos fails into this device category, so I decided to give this set up a chance. Plus, SqueezeCenter would allow comfortable controlling, or so I thought.

Sort of a solution

Setting up a whole digital music managing suite wasn't nearly as complex as I thought it would be. But soon, I found out the advantages as well as the disadvantages:

The good

SqueezeCenter “knows” if a client is connected and only streams by then, so I wouldn't have to worry about wasted traffic and bandwidth. Selecting BBC stations (with an additional plugin to be mentioned next paragraph) is a breeze, at least in a web browser.

Nice bonus: you can virtually use any source to stream from that SqueezeCenter supports, and whatever the source material is, it outputs an MP3 stream, so this set up wouldn't be restricted to BBC Internet radio streams.

The bad

You'll need to connect your device, be it hard- or software, to SqueezeCenter first, before you can select a source and play it, stop it, skip it etc. Technical limitations also occur, as SqueezeCenter does not support RealAudio streams.

(Luckily, that wasn't a dead end, as it appears I'm not the only SqueezeCenter user who wants to listen to the BBC. A single web search revealed the great SqueezeCenter plugin fittingly called “AlienBBC”. Basically, it takes the BBC Internet radio streams in RealAudio and converts them to the mentioned MP3 stream – using MPlayer.)

The ugly

AlienBBC really played the alien. Not the Ripley one, more like the one you can see but not talk to: It's not allowing the stream to be played over the Internet.

There were other technical nightmares you can't imagine. Did you know there must be a file descriptor in hell?

Also, you have to change stations via the SqueezeCenter web interface (in the software only solution).

Making it work

Some technical mumbo-jumbo later I nicely integrated AlienBBC. This required fairly simple hacking, as it was very easy to bypass AlienBBC's routine to check if the connected device is a “slim device”, the hardware counter part to SqueezeCenter. Without this limitation, AlienBBC would allow streaming just to everywhere where SqueezeCenter does.

More of a problem was the internal process that actually converts RealAudio to MP3. This time, it was neither SqueezeCenter's nor AlienBBC's fault, rather the place where the conversion takes place in the operating system – it didn't exist. This really took me some time to figure out, but once I knew this and the “why” I could easily fix it. Finally, it was possible to listen to AlienBBC wrought Internet streams.

But still, I had to connect the device first and then select the appropriate station in the web interface. It was working, but not in a convenient way.

Giving it the final touch

Which is the most convenient way then? Just to add an URI a station in the Sonos, without connecting it first, ever leaving the couch and surfing to the web interface, changing stations, getting back to the couch!

Ideally, this would mean feeding the Sonos URIs like http://[that server]/[that station]. While this URI scheme didn't work for proxying, it surely would for this SqueezeCenter set up, as it wasn't a proxy anymore. The SqueezeCenter appears as an own content provider. So instead of using this “URI proxy scheme”, I'd use the idea to change stations.

I searched the web again and figured out how to control the SqueezeCenter's web interface via an URI. With this knowledge, I finally could write a script that would handle this whole URI-only scenario. All this script does – simply put – is taking the station from the provided URI, return the SqueezeCenter stream to the player, wait two seconds so SqueezeCenter has a connected client, then to change stations and play it. I wouldn't even have to take care of a disconnected player because SqueezeCenter does.

In the end, it finally was possible just to use an URI as proposed by the very first hypothetical scenario without further setup, no physical interaction. It just looks and works like it, only it does something different in the background.

What about the iPlayer?

Getting the iPlayer to work was a complete no-brainer, as this really works with a simple proxy set up on that server to be used in your favourite browser. Boring.

Adventurous side notes worth mentioning

  • You don't want to mess with Plesk if you need an up-to-date server you want to play around with. I'm sorry, Parallels, using Plesk for server administration is like domesting dinosaurs: It was fun to watch in Jurassic Park, but in the end they're extinct for a reason.
  • BBC productions are pretty cool. Their radio moderators know – and sing – the DuckTales tune, they've got Doctor Who and collaborated with Douglas Adams.
  • I know Rhapsody features BBC stations.
  • About 20 cans of white tea were consumed to get this whole project to work as it is by now.
  • No animals, including dinosaurs, were harmed.
  • Sadly, only one cake had to give his life.

Wonderland revisited

Shortly after I published this how-to, James Cridland left a comment on the “adventure” and how-to pointing out it's possible to listen to BBC Internet radio worldwide. During the development process, which lays back some weeks already now, it wasn't possible to do so. Of course we tried accessing the BBC streams directly from both Switzerland and Germany, and it failed. Now, the journey shortly continued, as I had to rewrite the how-to. Alice, bring in the cake!

But now, without further ado, let me reveal the magic in technical details!

How to listen to BBC Internet radio streams on a Sonos or any other MP3 streaming device

  1. Purpose
  2. Notes
  3. Prerequisites
  4. Let's go to work
  5. Final words

Purpose

The goal is to be able to listen to BBC Internet radio streams on a Sonos or any other streaming device that supports MP3 streams in the most convenient way: by just adding an URI a station. Optionally, to be able to use the BBC iPlayer outside the UK.

Notes

[text] is a string that you need to replace with something else. Don't get me wrong, I don't think you're stupid, but other people are: Replace it completely – including “[” and “]” – with the string to be named, e.g., [text] may become your text.

Prerequisites

  • You understand and agree (1) that this how-to is purely educational, and (2) that by implementing the knowledge you gain by this how-to you actually may break some laws / insult UK tax payers / run out of cake.
  • You'll need some time, about an hour or so, and cake. Tea (I dig “White Oothu”) is optional.
  • You need some basic skills in Linux/Unix, or the will to politely ask and patiently wait in the comments for details, if required.
  • You need a set up and running server (like a dedicated server or any other machine you have extensive access to, a Linux home server might already serve that purpose). It needs to be physically in the UK (as you need an UK IP adress) if you want to use the BBC iPlayer.
    This is not a recommendation, but Webfusion's Virtual Private Server works for me, so it might for you, too.
  • Your server is running a web server (like Apache – the most basic setup will be enough already) that supports PHP.
  • Your server has cURL installed.
  • You already have a working copy of SqueezeCenter installed on this server.
    (I easily installed it on Ubuntu 7.10 adding the Slim Devices apt-package repository; for help installing please either consult the Slim Devices Wiki or refer to the third requirement.)
  • You already have installed AlienBBC (check their installation instructions, too, or refer to the third requirement, again) on this server, too.
  • For using the BBC iPlayer
    You've got a running copy of a proxy server (like Squid) on the very same server.
    For your convenience, I highly recommend using Firefox with the FoxyProxy extension.
  • Download this file (3.35 KiB) and don't forget where it is. You will need it later.

Let's go to work

I assume SqueezeCenter is running and working already. You can easily test it by pointing a software player like VLC or iTunes to http://[your server URI]:9000/stream.mp3 (where [your server URI] is the adress of your server, like “my.server.webfusion.co.uk”). Then, visit SqueezeCenter (http://[your server URI]:9000) and tune in into a Shoutcast station. Within a few seconds, you should hear something. Working? Great! Treat yourself with some moist cake. Not working? Get it working and treat yourself with some cake in the meantime.

Is AlienBBC working? You can see if the plugin is correctly installed if AlienBBC shows up under the Internet Radio tab in SqueezeCenter. Don't expect the provided streams to be working already, because they won't, and I'd had no how-to to write.

Also in SqueezeCenter, you'll have to make sure it knows what to do internally with AlienBBC provided streams. Head to SqueezeCenter's Settings → Advanced → File Types, search for RTSP, head right to MP3, and select MPlayer.sh/lame, then hit apply.

While you're at it, we need to change some security settings. Head over to Settings → Advanced → Security, set CSRF Protection Level to None. Hit apply. We'll check back later to increase security, but in the meantime you'll have to stick at this.

Now you'll have to do some Unix command line mojo to verify some things. Log in to your server using SSH, become “root” (With great power comes great responsibility) and head to the directory /dev/fd. If it exists, good! If this directory does not exist, don't worry, it's just somewhere else, so let's create a link to it by using this command: ln -s /dev/fd /proc/self/fd

Next, we'll have to modify AlienBBC. Currently, it does only allow “slim clients”. We need to change that, so we can enjoy AlienBBC virtually everywhere from any device. For this, you'll just have to comment out six lines in a single file. Open RTSP.pm in your AlienBBC plugin folder (on your server, or locally, but don't forget to upload it afterwards), and comment out lines 34-40 by putting a # in front of each line. It's the part that says Check client - only stream to known slim clients.

Restart SqueezeCenter now (on Ubuntu with the command /etc/init.d/slimserver restart), as you're now half set. You can already listen to the BBC! Connect a software client to your stream (http://[your server URI]:9000/stream.mp3), and in SqueezeCenter, tune in into, for example, BBC 1 listen live. Wait some seconds – there you go! If not, well, there may be some AlienBBC issues. Check their FAQ again or contact me.

If things are working as they're supposed to do, you may want to set up some security settings. Remember the security preferences pane? Show off your knowledge, go back to it, and put in a user name and a password. Please, please remember those.

Now, the current scenario isn't completely convenient as you'd have to tune in into the stream with your Sonos, get off the couch, open the SqueezeCenter web interface, switch stations, get back to your couch and your Sonos, and listen to it. Why not just have a single URI for each major BBC station so you can save it as a favourite in your Sonos and directly tune into it without getting your behind of the couch? Let's do that!

Remember the file you downloaded? Unzip it, as you'll need to change one of them. Open “index.php” in your favourite text editor as you need to make some changes in it. They're pretty straight forward as I prepared them for easy set up. Go the “Settings” in it, and fill out the required text fields.

Upload the modified file (index.php) and the other file (curl.tmp) to your web server. If you're using the server just for streaming and proxying issues, you may want to put those files into your web server's root directory. If you're running other web services already, put them into an easy to remember folder, like “radio”. In the end, you should be able to access them in a convenient way, like http://[your server]/index.php or http://[your server]/radio/index.php. Open this URI for testing purposes in your browser. You should read “It works!”. If not, well, you know what to do now, because you didn't.

If you're still smiling, and ate pretty much cake, this means you're just so close from a happy ending. In your Sonos, you can now enter the following URIs (case sensitive):

  • http://[your server]/?station=BBC1 (or e.g. http://[your server]/radio/?station=BBC1, or whatever you set up – valid for the following examples, too) for BBC 1
  • http://[your server]/?station=BBC2 for BBC2
  • http://[your server]/?station=BBC3 for BBC3
  • http://[your server]/?station=BBC4FM for BBC4 FM
  • http://[your server]/?station=BBC4LW for BBC4 LW
  • http://[your server]/?station=BBC5 for BBC5
  • http://[your server]/?station=BBC5X for BBC5 Sports Extra
  • http://[your server]/?station=BBC6 for BBC6 Music Live
  • http://[your server]/?station=BBC7 for BBC7
  • http://[your server]/?station=BBC1X for BBC1X

Please note that tuning in takes about 15-20 seconds due to caching. But isn't it worth it? Also, you've got a nice bonus, as you're now ready to use your Sonos for almost any Internet radio station on this planet! Just use the following URI:

  • http://[your server]/?station=X&uri=[your URI] where [your URI] is any valid streaming URI, like http://metafiles.gl-systemhaus.de/dw/radio_de.ram for Deutsche Welle.
    Applying this example would look like: http://[your server]/?station=X&uri=http://metafiles.gl-systemhaus.de/dw/radio_de.ram

You made it! Congratulations!
Plus, if your server is in the UK and has a set up proxy server, you can now also use the BBC iPlayer. If you followed my recommendation and use Firefox with FoxyProxy, use the following wildcard to restrict your proxy only to the BBC: *.bbc.co.uk/*.

Final words

Did you enjoy your cake? Great. And now that you own the BBC, too, I hope you know what to do with this thing. Enjoy listening to and viewing the BBC in the currently most convenient way. If you liked this how-to, let me know, if it worked out as expected, let me know, if you don't or it didn't, let me know, too.

Do you have a challenging problem that you'd like to get solved? Don't hesitate to contact me! Also, you can Ask My Dog.

Oh, affiliation disclosure: Sonos is a portfolio company of my employer, BV Capital.

The End. What's Next?

If you liked this post Sign up for the site feed sign up for the site feed or subscribe via email. You might as well have a look at the archives or go home.

Comments

2008.03.25

James Cridland+

You say "It's per se not possible to listen to and view any of the BBC Internet streams if you live outside the UK"

Might I confirm that all the BBC's RealAudio radio streams are available worldwide. No hacking required (fun though all this looks!). It's just as simple as pointing anything that plays RealAudio to our streams.

In addition, Windows Media streams of our stations may be available, subject to this pseudo-code:
if ($station > 4) {it's available}
…i.e. BBC Radio 4 is not; BBC Radio 5 live is.

Thank you for listening,

James Cridland, Head of FM&T, BBC Radio

Benjamin Wittorf+

James – thank you very much for pointing this out. I'll update the how-to accordingly.

For the record, though, I'd like to mention that at the time of developing this solution it wasn't possible to listen to BBC Internet radio streams outside the UK (tested from Switzerland and Germany some weeks ago). Do you mind telling me if we were wrong or if the IP policy has just changed?

James Cridland+

If you can't get the RealAudio portions of the BBC Radio Player outside of the UK, please do follow the contact-us link and we'll investigate. There are some programmes we are unable to stream internationally; and Windows Media streams are restricted as mentioned.

2008.03.26

Benjamin Wittorf+

Sonos Forums user “corner_back” kindly started a new forum thread for discussing technical aspects of this how-to. You're of course still welcome to leave a comment on this entry, but you may want to give the forums a visit as well.

2008.03.27

corner_back+

Grüße aus München!
Thanks a million Benjamin for coming up with this way of getting real streams in a Sonos compatible format.

As I mentioned on the Sonos fourms, I have got as far as a manually chosen output from SqueezeCentre.

I will try and get the remote changing of streams working tonight if I have time.
From the looks of it it is pretty straight forward.

If it is as easy as I think, then maybe a next step would be to get the instructions for the common user as simple as possible.

An all-in-one installer for windows would also be trivial to put together, with all necessary installers in one downloadable self executable, which you could run to install and configure everything in a couple of clicks of a mouse.

My only question is whether it is allowed, legally I mean, to supply a changed config file of the AlienBBC to allow non squeeze clients? I couldnt find any licence terms in the installed plugin.

Benjamin Wittorf+

corner_back – you're welcome! Thank you for trying out the how-to and applying it to a Windows scenario, as well as writing it down.

AlienBBC is released under the GPL (from their site: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2), so you should be allowed to modify it in any way you'd like to. SqueezeCenter is also released under the GPL.

I really like the idea of streamlining (and integrating the Windows part into) this how-to. Also, it's a great idea to make an installer for Windows. As for Linux, I'd rather only provide the modified AlienBBC plugin because I presume Linux/Unix users know what they're doing.

Leave A Comment

Be kind

Thanks for leaving a comment. Constructive criticism is appreciated.

Fields marked with an asterisk (*) are required.
You may use basic HTML to spice up your comment.


About This Post

If you want to listen to BBC Internet radio streams on a Sonos or any other MP3 streaming device for that matter, this how-to is just for you. Features the preceding adventure. What a journey!

Possibly related:

Et cetera

Made on a Mac and published with MTOS.

Contents licensed under the Creative Commons.


Categories