<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; id3</title>
	<atom:link href="http://blog.flexexamples.com/tag/id3/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Displaying a dynamically loaded MP3 file&#8217;s ID3 information in Flex using the SoundEffect class</title>
		<link>http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex-using-the-soundeffect-class/</link>
		<comments>http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex-using-the-soundeffect-class/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 06:34:46 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ID3Info]]></category>
		<category><![CDATA[SoundEffect]]></category>
		<category><![CDATA[duration]]></category>
		<category><![CDATA[id3]]></category>
		<category><![CDATA[isPlaying]]></category>
		<category><![CDATA[useDuration]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex-using-the-soundeffect-class/</guid>
		<description><![CDATA[<p>In a previous example, <a href="http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex/">&#8220;Displaying a dynamically loaded MP3 file&#8217;s ID3 information in Flex&#8221;</a>, we saw how to load an MP3 into Flex using the Sound class.</p> <p>The following example shows you how you can dynamically load and play an MP3 in Flex using the SoundEffect class, and access the Sound object and it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous example, <a href="http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex/">&#8220;Displaying a dynamically loaded MP3 file&#8217;s ID3 information in Flex&#8221;</a>, we saw how to load an MP3 into Flex using the Sound class.</p>
<p>The following example shows you how you can dynamically load and play an MP3 in Flex using the SoundEffect class, and access the Sound object and it&#8217;s ID3 information.</p>
<p>Full code after the jump.</p>
<p><span id="more-545"></span></p>
<p class="construction">I didn&#8217;t include all the MP3 files in the source code ZIP. You can download the MP3s from <a href="http://ghosts.nin.com/main/order_options" target="_blank">http://ghosts.nin.com/main/order_options</a>. Hooray for free Nine Inch Nails songs and Creative Commons licensing!</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/SoundEffect_sound_id3_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex-using-the-soundeffect-class/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.utils.ObjectUtil;

            private const NIN_URL:String = "http://ghosts.nin.com/";

            private function playSoundEffect(src:String):void {
                textArea.text = "";

                if (soundEffect.isPlaying) {
                    soundEffect.stop();
                }
                soundEffect.source = src;
                soundEffect.play([soundEffect]);
            }

            private function soundEffect_id3(evt:Event):void {
                var id3Info:ID3Info = Sound(soundEffect.sound).id3;
                textArea.text += ObjectUtil.toString(id3Info);
                textArea.text += "\\n\\n-------------------\\n\\n";
            }

            private function comboBox_change(evt:Event):void {
                var cb:ComboBox = evt.currentTarget as ComboBox;
                playSoundEffect(cb.selectedItem.@source);
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:XML id="playlist" source="data/playlist.xml" /&gt;

    &lt;mx:SoundEffect id="soundEffect"
            duration="10000"
            useDuration="true"
            id3="soundEffect_id3(event);" /&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:ComboBox id="comboBox"
                prompt="Please select a song..."
                dataProvider="{playlist.song}"
                labelField="@title"
                change="comboBox_change(event);" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:TextArea id="textArea"
            editable="false"
            width="100%"
            height="100%" /&gt;

    &lt;mx:LinkButton id="linkButton"
            label="All songs copyright Nine Inch Nails (2008)"
            click="navigateToURL(new URLRequest(NIN_URL), '_blank');" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/SoundEffect_sound_id3_test/playlist.xml">View playlist.xml</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex-using-the-soundeffect-class/ --&gt;
&lt;playlist&gt;
    &lt;song title="Track 1" source="assets/01 Ghosts I.mp3" /&gt;
    &lt;song title="Track 2" source="assets/02 Ghosts I.mp3" /&gt;
    &lt;song title="Track 3" source="assets/03 Ghosts I.mp3" /&gt;
    &lt;song title="Track 4" source="assets/04 Ghosts I.mp3" /&gt;
    &lt;song title="Track 5" source="assets/05 Ghosts I.mp3" /&gt;
    &lt;song title="Track 6" source="assets/06 Ghosts I.mp3" /&gt;
    &lt;song title="Track 7" source="assets/07 Ghosts I.mp3" /&gt;
    &lt;song title="Track 8" source="assets/08 Ghosts I.mp3" /&gt;
    &lt;song title="Track 9" source="assets/09 Ghosts I.mp3" /&gt;
&lt;/playlist&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/SoundEffect_sound_id3_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/SoundEffect_sound_id3_test/bin/main.html" width="100%" height="400"></iframe></p>
<p class="note">Note that the SoundEffect only plays the first 10 seconds of each song. If you wanted to play the full song, simply omit the <code>duration</code> property in the &lt;mx:SoundEffect /&gt; tag, and set the <code>useDuration</code> property to <code>false</code>.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Displaying a dynamically loaded MP3 file\&#039;s ID3 information in Flex using the SoundEffect class on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex-using-the-soundeffect-class/',contentID: 'post-545',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'duration,id3,isPlaying,useDuration',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex-using-the-soundeffect-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Displaying a dynamically loaded MP3 file&#8217;s ID3 information in Flex</title>
		<link>http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex/</link>
		<comments>http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 02:18:03 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[ID3Info]]></category>
		<category><![CDATA[Model]]></category>
		<category><![CDATA[Sound]]></category>
		<category><![CDATA[id3]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex/</guid>
		<description><![CDATA[<p>The following example shows how you can dynamically load an MP3 file into Flex using the Sound class and get the MP3 file&#8217;s ID3 information using the id3 event (Event.ID3) and the Sound object&#8217;s id3 property.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Sound_id3_test/main.mxml">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can dynamically load an MP3 file into Flex using the Sound class and get the MP3 file&#8217;s ID3 information using the <code>id3</code> event (<code>Event.ID3</code>) and the Sound object&#8217;s <code>id3</code> property.</p>
<p>Full code after the jump.</p>
<p><span id="more-544"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Sound_id3_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.utils.ObjectUtil;

            private const URL:String = "http://www.helpexamples.com/flash/sound/song2.mp3";
            private var sound:Sound;
            private var soundLoaderContext:SoundLoaderContext;

            private function loadSound(url:String):void {
                var urlRequest:URLRequest = new URLRequest(url);
                // Check policy file
                soundLoaderContext = new SoundLoaderContext(1000, true);

                sound = new Sound();
                sound.addEventListener(Event.ID3, sound_id3);
                sound.load(urlRequest, soundLoaderContext);

                textArea.text = "";
            }

            private function sound_id3(evt:Event):void {
                var id3Info:ID3Info = Sound(evt.currentTarget).id3 as ID3Info;
                textArea.text += ObjectUtil.toString(id3Info);
                textArea.text += "\\n---------- ---------- ----------\\n";
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Button id="button"
                label="Load MP3"
                click="loadSound(URL);" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:TextArea id="textArea"
            editable="false"
            width="100%"
            height="100%" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/Sound_id3_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/Sound_id3_test/bin/main.html" width="100%" height="250"></iframe></p>
<p>The following example shows how you can use data binding to update values in a Label control using a Model:</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            private const SONG1:String = "http://www.helpexamples.com/flash/sound/song1.mp3";
            private const SONG2:String = "http://www.helpexamples.com/flash/sound/song2.mp3";

            private var sound:Sound;
            private var soundLoaderContext:SoundLoaderContext;

            private function loadSound(url:String):void {
                var urlRequest:URLRequest = new URLRequest(url);
                // Check policy file
                soundLoaderContext = new SoundLoaderContext(1000, true);

                sound = new Sound();
                sound.addEventListener(Event.ID3, sound_id3);
                sound.load(urlRequest, soundLoaderContext);
            }

            private function sound_id3(evt:Event):void {
                model.id3info = Sound(evt.currentTarget).id3;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Model id="model"&gt;
        &lt;model&gt;
            &lt;id3info&gt;&lt;/id3info&gt;
        &lt;/model&gt;
    &lt;/mx:Model&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Button label="Song 1" click="loadSound(SONG1);" /&gt;
        &lt;mx:Button label="Song 2" click="loadSound(SONG2);" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:Form&gt;
        &lt;mx:FormItem label="album:"&gt;
            &lt;mx:Label text="{model.id3info.album}" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="artist:"&gt;
            &lt;mx:Label text="{model.id3info.artist}" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="songName:"&gt;
            &lt;mx:Label text="{model.id3info.songName}" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="track:"&gt;
            &lt;mx:Label text="{model.id3info.track}" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="year:"&gt;
            &lt;mx:Label text="{model.id3info.year}" /&gt;
        &lt;/mx:FormItem&gt;
    &lt;/mx:Form&gt;

&lt;/mx:Application&gt;
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Displaying a dynamically loaded MP3 file\&#039;s ID3 information in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex/',contentID: 'post-544',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'id3',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
<enclosure url="http://www.helpexamples.com/flash/sound/song2.mp3" length="195948" type="audio/mpeg" />
<enclosure url="http://www.helpexamples.com/flash/sound/song1.mp3" length="339517" type="audio/mpeg" />
<enclosure url="http://www.helpexamples.com/flash/sound/song2.mp3" length="195948" type="audio/mpeg" />
<enclosure url="http://www.helpexamples.com/flash/sound/song1.mp3" length="339517" type="audio/mpeg" />
<enclosure url="http://www.helpexamples.com/flash/sound/song2.mp3" length="195948" type="audio/mpeg" />
<enclosure url="http://www.helpexamples.com/flash/sound/song1.mp3" length="339517" type="audio/mpeg" />
		</item>
	</channel>
</rss>

