Flash MX 2004 MP3 Player Pg.3

source: http://www.thegoldenmean.com/

3 — PHP

The PHP Scripts

Using PHP to generate a dynamic PlayList was considered in considerable depth in the second tutorial of this series. This page will merely review what the three scripts do and touch on several significant changes to the songList.xml.php file.

What scripts are we talking about?

Three PHP scripts are provided in the project files download. Two are written by Daniel Martinez–Morales: ID3v2.php and arrays.php. The third was written by Tilo Kussatz: songList.xml.php.

Where are the Scripts Placed?

All three PHP scripts must be placed in the tracks subdirectory(along with all your MP3 assets) in order for this to work. Please note that this is different from the approach taken in tutorials one and two, where everything was tossed into the same folder regardless of whether it was PHP, MP3, .swf or html.

What do the Scripts Do?

The goal is to produce an XML file containing several important bits of information about each track. The Flash Player will parse this XML file and use it as a PlayList. If that were all, a hand-coded PlayList (such as was discussed in the first tutorial) would be a lot less bother. But the real goal is to do what was previously stated automatically. It is possible, common in fact, to embed meta data in an MP3 file in what are known as ID3 tags. This embedded information can include, among many other things, title, artist and album information.

The wonderful PHP Classes written by Mr. Martinez–Morales find and extract any data contained in MP3 files’ ID3 tags. The equally wonderful script by Mr. Kussatz writes the complete XML PlayList document based on some of the extracted information. The result of these three scripts is that MP3 files can be added to or taken out of the tracks folder and the PlayList updates automatically!

This is of course based on the assumption that your MP3 files contain ID3 tags with meaningful information for the script to extract! There are numerous software products (many of them free) which enable you to examine, create and modify ID3 tags and data. I use iTunes on my Mac. WinAmp is popular on Windows based PCs

What do I need to know to make them work?

Really only one thing - a web server is required to execute the PHP scripts. They won’t do anything on your local computer (unless of course you are running a web server on your local computer. Many contemporary computers have that option available.) If you aren’t running a web server locally, you will need to upload the files to a conventional web hosting service to test your project.

But that’s about it — you don’t need to do anything else (in fact, you shouldn’t do anything to the ID3v2.php and arrays.php scripts). Everything will work just fine right “out of the box”.

There have in fact been several quite significant changes made to songList.xml.php since the second tutorial in this series. In fact, we might call this version expanded and improved!


The earliest version of this script only needed to provide a track title and the path to that asset. The title was all the Player had room to display in its ListBox component. Because this version’s infoTxt text field will grow to accomodate any quantity of text, we might as well put more in it, information such as artist and album. In addition, in order to animate the position progress bar we need to know immediately how long the track is. The information the new playlist makes available to the Player now includes:

One line from the XML playlist file used in the examples in this tutorial looks like this:

<song artist="Freeplay Music Inc." title="Clearing"
   album="World Mix Volume 1" playtime="33097" filesize="682732"
   url="tracks/Clearing.mp3" />


It was discovered that at least some versions of the Apache Web Server organize files by date added, NOT alphabetically. This was really confusing people who quite reasonably assumed their tracks would be played in alphabetical order. Mr. Kussatz modified his original songList.xml.php script to permit sorting by several criteria. The default is alphabetical. Instructions for sorting by other criteria are contained in the comments within the script itself.

That really was a brief discussion, but it should suffice. It’s time to start making your Player. We will begin by making the visual assets on page four.

go to page: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14
divider ornament