Day 15 - Streaming mp3s with Catalyst

A very short article about a very simple streaming server.


Just a short entry for today, briefly describing one of the examples in the Catalyst subversion repository.

In December 2005 Andy Grundman wrote a very short streaming server for Catalyst which you can obtain by issuing the command:

  $ svn co

In simple terms, a streaming server is a web server that dynamically throttles the delivery of large media blobs on a per-user basis. The server in this example is really a proof of concept which shows you the basic technique to get started with.

Because this example is relatively old (by Catalyst standards) there is no Controller::Root, which is now the recommended practice - the root controller is in

After you've gotten the example, copy an mp3 file into the application root and call it test.mp3).

Next up, you're going to have to find an mp3 player that supports streaming - for this example we just send the file directly so we don't have to mess around with embedding and Javascript to get it to play in the browser properly. So I used mplayer:

  $ mplayer http://localhost:3000/mp3

You can see the mp3 controller dealing with the request in the debug output - telling you how many bytes it spits out at each time. If you can pause mplayer before the file has finished downloading, you can see that the server stops responding as well. I have been unable to get the range request output for this server, but would be interested to hear how.

In any case, the code is available to download, and as with all things Catalyst, it's easy and simple to adapt this code to suit your own purposes.


Kieren Diment, <> (article) Andy Grundman, <> (streaming server)