I had the pleasure of making it out to the Philadelphia branch of the Adobe AirBus tour last week, held at the Ben Franklin Institute of science. My friend and I managed to get there just as Ryan Stewart was giving his keynote speech, so we grabbed our free bag of swag and a t-shirt and went on in. All in all it was a very cool event, and even though I’ve been working with Flex and Air for a while now I walked away with a lot of great resources and ideas. The highlight of my evening was that I was able to speak with Mike Chambers during the intermission about how to do a few things in Air that I’d been struggling with. Mike is a super friendly guy and was very helpful. He even offered to throw together some examples for me while he was on the road. Thanks for the help Mike, and thanks to the rest of the tour members who came out to Philadelphia.
ian AS3.0, Air, Flex, News
I took a bit of time to convert the itunesXMLParser class into a full fledge Flex component.
You can download the SWC here
Heres a bit of usage:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
xmlns:im="org.im.*"
>
<im:itunesXMLParser
id="ixml"
sourceXML="testlibrary.xml"
complete="dg_mx.dataProvider=ixml.data"/>
<mx:DataGrid id="dg_mx"
width="80%"
height="40%"
rowCount="10"
verticalCenter="4"
horizontalCenter="0">
<mx:columns>
<mx:DataGridColumn dataField="Track_ID" headerText="Track_ID"/>
<mx:DataGridColumn dataField="Name" headerText="Name"/>
<mx:DataGridColumn dataField="Artist" headerText="Artist"/>
<mx:DataGridColumn dataField="Genre" headerText="Genre"/>
<mx:DataGridColumn dataField="Kind" headerText="Kind"/>
<mx:DataGridColumn dataField="Size" headerText="Size"/>
<mx:DataGridColumn dataField="Total_Time" headerText="Total Time"/>
<mx:DataGridColumn dataField="Date_Modified" headerText="Date Modified"/>
<mx:DataGridColumn dataField="Date_Added" headerText="Date Added"/>
<mx:DataGridColumn dataField="Bit_Rate" headerText="Bit Rate"/>
<mx:DataGridColumn dataField="Sample_Rate" headerText="Sample Rate"/>
<mx:DataGridColumn dataField="Release_Date" headerText="Release Date"/>
<mx:DataGridColumn dataField="Sort_Album" headerText="Sort Album"/>
<mx:DataGridColumn dataField="Sort_Name" headerText="Sort Name"/>
<mx:DataGridColumn dataField="Persistent_ID" headerText="Persistent ID"/>
<mx:DataGridColumn dataField="Track_Type" headerText="Track Type"/>
<mx:DataGridColumn dataField="Podcast" headerText="Podcast"/>
<mx:DataGridColumn dataField="Unplayed" headerText="Unplayed"/>
<mx:DataGridColumn dataField="Location" headerText="Location"/>
<mx:DataGridColumn dataField="File_Folder_Count" headerText="File Folder Count"/>
<mx:DataGridColumn dataField="Library_Folder_Count" headerText="Library Folder Count"/>
</mx:columns>
</mx:DataGrid>
This line shows the usage of the component
<im:itunesXMLParser
id="ixml"
sourceXML="testlibrary.xml"
complete="dg_mx.dataProvider=ixml.data"/>
This allows you to easily specify an itunes library file as a source for the component and then use the complete listener to perform some action once the data has been loaded. In this case I’m binding it to the dataProvider property of my DataGrid component.
This shows you how to set up the xml namespace so you can use the im:itunesXMLParser tag to instantiate the component. Also, don’t forget to include the .swc file into your library path in the project settings.
ian News

Ok, so first off let me say that the iTunes playlist XML structure looks like it was designed by someone who doesn’t even know XML.
Take a look at this entry for a single song:
<dict>
<key>Track ID</key><integer>64</integer>
<key>Name</key><string>Episode 14</string>
<key>Artist</key><string>Gareth Emery</string>
<key>Album</key><string>The Gareth Emery Podcast</string>
<key>Genre</key><string>Podcast</string>
<key>Kind</key><string>MPEG audio file</string>
<key>Size</key><integer>64803919</integer>
<key>Total Time</key><integer>2700068</integer>
<key>Year</key><integer>2006</integer>
<key>Date Modified</key><date>2006-09-21T15:14:43Z</date>
<key>Date Added</key><date>2006-09-21T15:14:43Z</date>
<key>Bit Rate</key><integer>192</integer>
<key>Sample Rate</key><integer>44100</integer>
<key>Play Count</key><integer>22</integer>
<key>Play Date</key><integer>3264149297</integer>
<key>Play Date UTC</key><date>2007-06-08T16:08:17Z</date>
<key>Release Date</key><date>2006-09-21T11:00:00Z</date>
<key>Sort Album</key><string>Gareth Emery Podcast</string>
<key>Persistent ID</key><string>FE2067001E4F2C00</string>
<key>Track Type</key><string>File</string>
<key>Podcast</key><true/>
<key>Location</key>
<string>The%20Gareth%20Emery%20Podcast/Episode%2014.mp3</string>
<key>File Folder Count</key><integer>4</integer>
<key>Library Folder Count</key><integer>1</integer>
</dict>
The way they have this structured makes it impossible to do any E4X based XML processing of the playlist and consequently prevents your from using it in Flex or any other MVC based framework that allows you to easily hook an XML data source into components on the view layer.
So, as if you couldn’t guess, I wrote a class so that you can. You can use it to load in an iTunes XML playlist and turn it into something use-able that adheres to XML best practice where the structure is concerned.
Heres a sample of what it outputs:
<song>
<Track_ID>511</Track_ID>
<Name>Episode 34</Name>
<Artist>Gareth Emery</Artist>
<Album>The Gareth Emery Podcast</Album>
<Genre>Podcast</Genre>
<Kind>MPEG audio file</Kind>
<Size>64804016</Size>
<Total_Time>2700068</Total_Time>
<Year>2007</Year>
<Date_Modified>2007-07-24T16:29:57Z</Date_Modified>
<Date_Added>2007-07-24T16:29:57Z</Date_Added>
<Bit_Rate>192</Bit_Rate>
<Sample_Rate>44100</Sample_Rate>
<Release_Date>2007-07-19T22:00:00Z</Release_Date>
<Sort_Album>Gareth Emery Podcast</Sort_Album>
<Sort_Name>Gareth Emery Podcast - Episode 34</Sort_Name>
<Persistent_ID>DFA5DE7CE96B0316</Persistent_ID>
<Track_Type>File</Track_Type>
<Podcast/>
<Unplayed/>
<Location>The%20Gareth%20Emery%20Podcast/Episode%2034.mp3</Location>
<File_Folder_Count>4</File_Folder_Count>
<Library_Folder_Count>1</Library_Folder_Count>
</song>
Much better, huh? Heres an example of how you can use it in your Flex/AS3.0 project.
var libraryPath:URLRequest = new URLRequest("testlibrary.xml");
iTunesLibrary = new itunesXMLParser();
iTunesLibrary.load(libraryPath);
iTunesLibrary.addEventListener(Event.COMPLETE, loadHandler);
iTunesLibrary.addEventListener(ProgressEvent.PROGRESS, progressHandler);
public function loadHandler(event:Event):void{
trace("Library is done loading, lets do something cool with it");
//trace(iTunesLibrary.playlistXML);
trace("songs: " + iTunesLibrary.playlistXML.song);
var songList:XMLList = iTunesLibrary.playlistXML.song;
//trace(songList);
dg_mx.dataProvider = songList;
}
public function progressHandler(event:ProgressEvent):void{
trace("progressHandler loaded:"
+ event.bytesLoaded + " total: " + event.bytesTotal)</code>
}
Note that it listens on all the same events as the normal XML class. In the loadHandler function above theres an example of how to hook this into a datagrid component in flex.
Thats it. Right now it only grabs songs, I’ll be adding support for multiple playlists later.
Download the class file here
Download the example flex project here
ian AS3.0, Flex, News, Projects