<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:fx="com.fusiox.ui.*" >
    <mx:Script>
        <![CDATA[
        import com.fusiox.media.ID3Stream;
        
        private function loadID3( file:String ):void {
            var stream:ID3Stream = new ID3Stream( new URLRequest(file) );
            stream.addEventListener( ProgressEvent.PROGRESS, onID3Progress );
            stream.addEventListener( Event.ID3, onID3Loaded );
        }
        
        private function onID3Progress( e:ProgressEvent ):void {
            if (e.target.length > 0  && e.bytesLoaded < e.target.length) {
                explorer.title = "ID3Stream Explorer [Loading " + Math.round(e.bytesLoaded/e.target.length*100) + "%]";
            } else {explorer.title = "ID3Stream Explorer";}
        }
        
        private function onID3Loaded( e:Event ):void {
            explorer.title = "ID3Stream Explorer";
            if (e.target.reader.img.length>0) { SongArt.loadBytes(e.target.reader.img); }
            SongTitle.text = e.target.reader.frames["TIT2"].text;
            SongArtist.text = e.target.reader.frames["TPE1"].text;
            SongAlbum.text = e.target.reader.frames["TALB"].text;
        }
        
        ]]>
    </mx:Script>
    <mx:Panel id="explorer" title="ID3Stream Explorer" horizontalAlign="left" verticalAlign="middle" paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10">
        <mx:HBox >
            <mx:VBox>
                <fx:Image id="SongArt" render="reflection.drawReflection();" />
                <fx:Reflection id="reflection" target="{SongArt}" width="{SongArt.width}" height="20" />
            </mx:VBox>
            <mx:VBox>
                <mx:Label id="SongTitle"/>
                <mx:Label id="SongArtist"/>
                <mx:Label id="SongAlbum"/>
            </mx:VBox>
        </mx:HBox>
        
        <mx:ControlBar horizontalAlign="right">
            <mx:Label text="MP3 URL:"/>
            <mx:ComboBox id="File" dataProvider="{new Array(&quot;http://www.benstucki.net/mp3/01 The One Infallible.mp3&quot;, &quot;http://www.benstucki.net/mp3/01 A Lot To Say.mp3&quot;, &quot;http://www.benstucki.net/mp3/02 Paternize.mp3&quot;)}" />
            <mx:Button label="Load" click="loadID3(File.text)"/>
        </mx:ControlBar>
    </mx:Panel>
</mx:Application>