Movable Type and Windows Media Player

GeekLeave a Comment

Got an e-mail from David this morning asking how I did the “Now Playing” sidebar item on my blog. I originally did all this work for integrating Radio Userland and Windows Media Player. That is how I stumbled onto this solution. If you don’t use Windows Media Player, this won’t help you. Sorry. I switch around my players so maybe I will investigate others someday. But this was just the first and easiest one to get going. Anyway, here is what you do:

1. Download the SongWriter plug-in for Windows Media Player. Follow the instructions on their web site for getting the plugin to work.

2. I setup the plug-in to publish my song information in a text file, songout.txt, to a music directory on my web site. Be sure its publishing the artist, album, song title, and small picture for my example code to work. Please verify that you get all this working by looking for the file on your web server.

3. Since I don’t want to rebuild my index.html page everytime the song changes, we need something dynamic to process this. I wrote a small PHP page that basically creates the JavaScript needed to draw the “Now Playing” text. This page parses the songout.txt file and then creates code to write HTML for a pretty sidebar entry. Here is my now_playing.php file for download. You can use it as a basis for yours.

4. Then, the final step is to integrate the “Now Playing” entry into your main template, or wherever you want it. Do this by including a script reference to that PHP file you created back in step 3. Mine looks like:


<script

type="text/javascript" src="/music/now_playing.php">

</script>

And that’s it. Your “Now Playing” entry on your home page will update very quickly after Windows Media Player switches songs. No page rebuilding necessary!