Article

Build a Yahoo Music Mashup with Adobe AIR

Page: 1 2 3 4 Next

When all the processing is complete, the method sends the ITUNES_ANALYSIS_COMPLETE message. Both of these messages are defined below:

File: ArtistEvent.as  
package com.videomashup  
{  
 import flash.events.Event;  
 
 public class ArtistEvent extends Event  
 {  
   public static const ITUNES_ANALYSIS_COMPLETE:String = 'ITUNES_ANALYSIS_COMPLETE';  
     
   public static const ARTIST_LIST_CHANGE:String = 'ARTIST_LIST_CHANGE';  
     
   public function ArtistEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)  
   {  
     super(type, bubbles, cancelable);  
   }  
     
 }  
}

The MXML code for our iTunes processing application looks like this:

File: iTunesVideos.mxml  
<?xml version="1.0" encoding="utf-8"?>  
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="onStartup()"  
 title="iTunes Artist List">  
<mx:Style>  
WindowedApplication { padding-bottom:10; padding-left:10; padding-right:10; padding-top:10 }  
</mx:Style>  
<mx:Script>  
<![CDATA[  
import com.videomashup.ArtistEvent;  
import com.videomashup.Artists;  
 
private function onStartup() : void {  
 Artists.instance.addEventListener( ArtistEvent.ITUNES_ANALYSIS_COMPLETE, onUpdateComplete );  
 
 var ar:ProgressWindow = new ProgressWindow();  
 ar.title = 'Scanning Artists';  
 ar.open( true );  
 
 Artists.instance.startReader();  
}  
 
private function onUpdateComplete( event:ArtistEvent ) : void {  
 artistList.dataProvider = Artists.instance.artists;  
}  
]]>  
</mx:Script>  
<mx:List width="100%" height="100%" id="artistList" labelField="name">  
</mx:List>  
</mx:WindowedApplication>

As you can see, there isn’t much to it! The application starts by registering an event handler that will listen for the completion of our iTunes library analysis. That handler then assigns the list box to the list of artists that were retrieved.

A progress window created by the application tells the user how much iTunes XML processing remains to be done. The code for this window is shown below:

File: ProgressWindow.mxml  
<?xml version="1.0" encoding="utf-8"?>  
<mx:Window xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="onStartup()"  
 styleName="main" width="300" height="70" horizontalAlign="center">  
<mx:Style>  
.main { padding-bottom:10; padding-left:10; padding-right:10; padding-top: 10; }  
</mx:Style>  
<mx:Script>  
<![CDATA[  
import com.videomashup.Artists;  
import com.videomashup.ArtistEvent;  
 
private function onStartup() : void {  
 prgBar.source = Artists.instance;  
 Artists.instance.addEventListener( ArtistEvent.ITUNES_ANALYSIS_COMPLETE, onFinished );  
}  
 
private function onFinished( event:Event ) : void {  
 close();  
}  
]]>  
</mx:Script>  
<mx:ProgressBar id="prgBar" label="Scanning %3%%" mode="polled" />  
</mx:Window>

This window launches and attaches the progress bar to the list of artists. The Artists class contains methods for bytesLoaded and bytesTotal, which are called by the progress bar automatically to obtain the current status. Then the window automatically closes when the “iTunes Analysis Complete” dialog is displayed.

Upon launching the application from Flex Builder, an empty main window will open, along with the progress window, as seen in Figure 1.

Figure 1. The iTunes Scanning Progress Indicator

When all the artists have been processed, the progress window will disappear. The list of artists is updated in the main window, as shown in Figure 2.

Figure 2. The iTunes Artist List

The next step is to merge the completed list of artists with the video service from Yahoo Music.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links