Creating a 24×7 radio station

December 3, 2011
By

Our light display runs nightly from 5pm – 11pm. That leaves 18 hours of dead air on my local radio station.  Now, to be sure, my “radio station” doesn’t broadcast much beyond my own block.  Nonetheless, I don’t like the idea of dead air.

It’s a radio station, so why not broadcast music during the show’s off hours?  Seemed like an easy proposition.  As usual, I discovered I have requirements. And those requirements don’t necessarily jive very well with the available packaged options I found. However, with a little ingenuity, I’ve created a solution that meets my requirements.

To start, here are those oh-so-important requirements:

  • I want to broadcast Christmas music, but I want a variety. I don’t have a big MP3 collection, so I wanted to make use of some Internet radio station.
  • I want any broadcast to start and stop before and after the light show is running. So, a scheduler will be necessary.
  • My radio transmitter supports RDS capability, so I’d like to be able to deliver the song title and artist name at the appropriate time.
  • I want all of this automated.  No manual operation.

There are lots of radio software applications available, such as Zara Radio.  These all work great, but are all about “hosted” music — shuffling through a big collection of MP3s or other music format types that are held on the local system running the application.  I want to incorporate an internet radio stream. And with that, I ran into a limited set of options.

First, most streaming music sources have a limited end client application that consumes the stream and plays it out.  The most popular streaming service, Pandora, uses either a Flash plug-in within a browser or an Adobe Air desktop application.  Other services follow much the same approach.

Based on what I discovered, there were a few things I was looking to find:

  • A streaming service that provided a Christmas music station, AND
  • A generic client application that could access any music stream, AND
  • A generic client application I could control from a scheduling basis, AND
  • A method of extracting artist + title information about the music.

Tough combination to find.  But, I found a working solution using Shoutcast, VLC, a custom application and the Windows Task Scheduler.

Shoutcast

Shoutcast is a streaming service that is now owned by a division of AOL. Shoutcast provides thousands (literally) of free internet radio stations, streaming music of all types and in all form of languages. Including, all kinds of Christmas songs!

I’ve met my first requirement – A streaming service that provided a Christmas music station.

Looking around and listening to the different stations, I found one I really liked.  But, I could only listen to it through the site’s webpage.  For my solution to work, I would need to access the stream directly.

Thanks to the magic powers of Google Chrome, I can easily discover the stream source. Shoutcast streams take the form of a URL, I just need to find it.

After loading the link to the Shoutcast Christmas stations in Chrome, opening the Developer Tools (wrench-button/Tools/Developer Tools) opens up a set of diagnostics to analyze the loaded web resource (in this case, Shoutcast’s web page.) You’ll see the tools at the bottom half of the screen.  On the black bar at the top of the bottom section that just appeared, click “Network”. On the web page itself, click on the play button of one of the stations.  In the Network section, all new resources requested by the browser are displayed as a result of clicking the play button. The resource we’re interested in: the URL for the station.

Each shoutcast station has a unique Id associated with it. Using this Id, you can build the url to acquire the streaming source.  A shoutcast radio station URL looks like this:

http://yp.shoutcast.com/sbin/tunein-station.pls?id=[station-id]&file=filename.pls

where [station-id] is an actual number, i.e. 12345. This query actually returns a bit of text that is used by the Shoutcast radio directory website to understand where to acquire a Shoutcast stream.

However, it also serves another purpose — a playable radio station. Look in the resource list under the “Network” section to find the URL. Next, I need a way to play the stream source through a stand-alone application.

VLC

Enter VLC, the open source all-purpose media player.

VLC is a free software package that can be used to play all manner of media files — audio, video, you name it. It runs on Windows, OSX and Linux operating systems. It plays local files as well as streaming sources. It’s the swiss army knife of media players.

As I mentioned, VLC is capable of playing most any streaming source. For my purpose, I simply needed it to play a Shoutcast stream. Turns out, it does. VLC is an amazing application. Not only does it run in all these environments, it can be initialized from command line. Ah, command line — the key to scriptable control.

VLC has a lot of capability, and the application can be started from the command line with an alarming number of switches and options. One of the options is a URL to a stream. So, let’s give that a try.

Simply starting vlc.exe with the stream name that we copied from the Shoutcast directory page, and I’ve got sweet music. This is exactly what I wanted, as I’ve met my second requirement – A generic client application that could access any music stream.

There’s an option I’m going to enable when I start VLC, the “-I” option. This loads any defined interface within VLC to allow some manner of control. We’re interested in the “http” interface, which provides us with some interesting information.

VLC Http interface

The Http interface option basically permits control of the VLC application through a web browser. When VLC is started with the “-I http” option, the desktop application doesn’t appear. Instead, if you open http://localhost:8080 in a web browser, you have controls of the VLC player coming through HTML.  Well, there are more options besides a web-based audio player.

In a web browser, open up http://localhost:8080/requests/status.xml.  In a nice structured format, all kinds of details about the currently playing source are displayed. Technical information about the sampling and bitrates, nature and state of the audio source, and lots of other statistics. There’s also a nice section of metadata, including “<now_playing>”.  This fulfills another requirement – A method of extracting artist + title information about the music.

I’ll need a nice query tool to pull this information out and write it out to a data file to supply as part of the RDS feed.  That’s a rather unique capability, so I’ll just create my own utility to do that.

 

VLCData

VLCData is a utility application I wrote specifically to pull the “now playing” information from VLC. This little application runs from the command-line and simply queries the VLC Http interface status.xml. It loads the resulting XML document, performs an XPath query to look for the <now_playing> node, and writes the results to a local file.  The local file is then picked up by another application that pushes RDS data to the FM transmitter.

The application queries the VLC interface every 10 seconds, and picks up changes when the source song changes. To make it more obvious, I also echo’d the currently detected song title and artist to the screen.

Next, I needed to be able to schedule the player to start and stop at prescribed times. While some developers have added specific scheduling functionality through add-ons, nothing fits the bill of what I want to accomplish — start and stop the stream of music at specified times.

This basically meant I couldn’t control the schedule from within VLC. So, I looked at what could control VLC externally.

Windows Task Scheduler/NirCmd

From the Start button, Task Scheduler can be found in Accessories/System Tools.  (This is on Windows 7, your navigation might be slightly different.)

Task Scheduler is exactly what it sounds like — a scheduled task to be run at specific times.  I have three tasks I created:

  1. StartupVLC, with certain parameters to play the music station I’m interested in hearing.
  2. StopVLC, using a command-line utility called NirCmd.
  3. RunVLCData, the command-line utility I created to pull song title+artist information from the VLC application.

“StartupVLC” executes command-line parameters to start the VLC application (vlc.exe) with a URL pointed to Shoutcast, and with the “-I http” interface option. This lets VLC run in the background, and I don’t have to bother with a desktop window.

“RunVLCData” runs the command-line utility (vlcdata.exe) for querying VLC for now-playing information. The application itself runs on a loop, so it simply needs to be started.

“StopVLC” uses the NirCmd utility to shutdown vlc.exe as well as vlcdata.exe.

The important setting around these tasks is the schedule. The show runs nightly from 5p-11p. With that, I want music to play outside those hours. So, the schedule for these tasks looks like this:

  • StartupVLC – runs daily at 11:05 pm. Because of how the application operates, it only needs to be started.
  • RunVLCData – runs daily at 11:05 pm. Same as StartupVLC.
  • StopVLC – runs daily at 4:55 pm. Kills the vlc and vlcdata processes.

That’s all there is to it. ;-)

Seriously, there are multiple working parts here but they all work in conjunction with each other. With some configurability, it permits me to run a holiday radio station 24/7 and especially when our display is off.

Leave a Reply

Your email address will not be published. Required fields are marked *