barking stars

March 30, 2005

Stream MP3s

If you don't want the preamble and just want the Greasemonkey script then click here.

What is this?

Rather than having to download MP3s before listening to them, this script will allow you to stream them in the form of M3U files. This script searches any page for links to MP3s and add a little icon after it (see an example here). Click the icon and the MP3 will stream in your favorite MP3 playing software.

Why would I want this?

It's a faster way of listening to MP3s that allows you to use a full featured media player. I used to stream audio using the Quicktime browser plugin however that has certain disadvantages as it has none of the whistles and bells you may enjoy in your MP3 player (such as an EQ for example). You also won't see any tag data.

What do I need to run this?
You will need:

  • Firefox as your browser
  • The Greasemonkey extension
  • An MP3 player that can play M3U files. Most do - in fact I haven't yet heard of any recent players that don't. I've tested this with both Windows Media Player and WinAmp.

How do I install it?

  • If you haven't already installed it, then go to this page and install Greasemonkey. Don't forget to restart Firefox afterwards.
  • Right click on this link and select "Install User Script..."
  • That's it! Now go to a site such as Viewropa or 3hive and you should see the icon next to the links

How does it work?

The script simply grabs the link to the MP3 file and passes it a specially created M3U file at this site. The M3U is dynamic - it uses PHP to insert the link to the MP3 into the file.

So that PHP can get access to the M3U file I added the following line to the .htaccess file:

   AddType application/x-httpd-php .m3u

The M3U file simply contains the following:
   <?php 
header("Content-Type: audio/x-mpegurl");
echo $s;
?>

Credit where credit is due

Credit is due to the author of the amazon2melvyl script - about all I did was change the variable names! Thanks to Julien Couvreur for the data url tip for the stream image - should save me a little bandwidth. Thanks to Brandon for telling me about a bug with URLs that have spaces in them. Thanks also to Pretty_Generic and his media streaming woes for inspiring this idea.

Changes

This script was changed 27/4/05 to fix URLs with spaces and other non-alphanumeric characters. If you already use this script I suggest you install it again.

Posted by Ivan at 06:43 PM