Flex中利用SoundEffect类动态显示MP3文件的ID3信息

在之前的 利用Flex的Sound类动态显示导入MP3文件时的ID3信息中,我们了解了如何利用Sound类将一个MP3文件load到Flex中。接下来的例子展示了如何利用SoundEffect类,动态读入MP3文件并且播放,以及访问Sound对象和它的ID3信息。
注意:源代码的压缩包中并没有包括全部的MP3文件,你可以到 http://ghosts.nin.com/main/order_options下载它们.万岁,免费的 Nine Inch Nails(乐队名称)歌曲以及创作共用许可(Creative Commons licensing)!
下面是全部的代码:
Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex-using-the-soundeffect-class/ -->
  3. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  4.         layout="vertical"
  5.         verticalAlign="middle"
  6.         backgroundColor="white">
  7.     <mx:Script>
  8.         <![CDATA[
  9.             import mx.utils.ObjectUtil;
  10.             private const NIN_URL:String = "http://ghosts.nin.com/";
  11.             private function playSoundEffect(src:String):void {
  12.                 textArea.text = "";
  13.                 if (soundEffect.isPlaying) {
  14.                     soundEffect.stop();
  15.                 }
  16.                 soundEffect.source = src;
  17.                 soundEffect.play([soundEffect]);
  18.             }
  19.             private function soundEffect_id3(evt:Event):void {
  20.                 var id3Info:ID3Info = Sound(soundEffect.sound).id3;
  21.                 textArea.text += ObjectUtil.toString(id3Info);
  22.                 textArea.text += "\n\n-------------------\n\n";
  23.             }
  24.             private function comboBox_change(evt:Event):void {
  25.                 var cb:ComboBox = evt.currentTarget as ComboBox;
  26.                 playSoundEffect(cb.selectedItem.@source);
  27.             }
  28.         ]]>
  29.     </mx:Script>
  30.     <mx:XML id="playlist" source="data/playlist.xml" />
  31.     <mx:SoundEffect id="soundEffect"
  32.             duration="10000"
  33.             useDuration="true"
  34.             id3="soundEffect_id3(event);" />
  35.     <mx:ApplicationControlBar dock="true">
  36.         <mx:ComboBox id="comboBox"
  37.                 prompt="Please select a song..."
  38.                 dataProvider="{playlist.song}"
  39.                 labelField="@title"
  40.                 change="comboBox_change(event);" />
  41.     </mx:ApplicationControlBar>
  42.     <mx:TextArea id="textArea"
  43.             editable="false"
  44.             width="100%"
  45.             height="100%" />
  46.     <mx:LinkButton id="linkButton"
  47.             label="All songs copyright Nine Inch Nails (2008)"
  48.             click="navigateToURL(new URLRequest(NIN_URL), '_blank');" />
  49. </mx:Application>
下面是歌曲List的XML文件:
Download: playlist.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex-using-the-soundeffect-class/ -->
  3. <playlist>
  4.     <song title="Track 1" source="assets/01 Ghosts I.mp3" />
  5.     <song title="Track 2" source="assets/02 Ghosts I.mp3" />
  6.     <song title="Track 3" source="assets/03 Ghosts I.mp3" />
  7.     <song title="Track 4" source="assets/04 Ghosts I.mp3" />
  8.     <song title="Track 5" source="assets/05 Ghosts I.mp3" />
  9.     <song title="Track 6" source="assets/06 Ghosts I.mp3" />
  10.     <song title="Track 7" source="assets/07 Ghosts I.mp3" />
  11.     <song title="Track 8" source="assets/08 Ghosts I.mp3" />
  12.     <song title="Track 9" source="assets/09 Ghosts I.mp3" />
  13. </playlist>

Flex中利用SoundEffect类动态显示MP3文件的ID3信息

By Minidxer | March 8, 2008
在之前的 利用Flex的Sound类动态显示导入MP3文件时的ID3信息中,我们了解了如何利用Sound类将一个MP3文件load到Flex中。接下来的例子展示了如何利用SoundEffect类,动态读入MP3文件并且播放,以及访问Sound对象和它的ID3信息。
注意:源代码的压缩包中并没有包括全部的MP3文件,你可以到 http://ghosts.nin.com/main/order_options下载它们.万岁,免费的 Nine Inch Nails(乐队名称)歌曲以及创作共用许可(Creative Commons licensing)!
下面是全部的代码:

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex-using-the-soundeffect-class/ -->
  3. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  4.         layout="vertical"
  5.         verticalAlign="middle"
  6.         backgroundColor="white">
  7.     <mx:Script>
  8.         <![CDATA[
  9.             import mx.utils.ObjectUtil;
  10.             private const NIN_URL:String = "http://ghosts.nin.com/";
  11.             private function playSoundEffect(src:String):void {
  12.                 textArea.text = "";
  13.                 if (soundEffect.isPlaying) {
  14.                     soundEffect.stop();
  15.                 }
  16.                 soundEffect.source = src;
  17.                 soundEffect.play([soundEffect]);
  18.             }
  19.             private function soundEffect_id3(evt:Event):void {
  20.                 var id3Info:ID3Info = Sound(soundEffect.sound).id3;
  21.                 textArea.text += ObjectUtil.toString(id3Info);
  22.                 textArea.text += "\n\n-------------------\n\n";
  23.             }
  24.             private function comboBox_change(evt:Event):void {
  25.                 var cb:ComboBox = evt.currentTarget as ComboBox;
  26.                 playSoundEffect(cb.selectedItem.@source);
  27.             }
  28.         ]]>
  29.     </mx:Script>
  30.     <mx:XML id="playlist" source="data/playlist.xml" />
  31.     <mx:SoundEffect id="soundEffect"
  32.             duration="10000"
  33.             useDuration="true"
  34.             id3="soundEffect_id3(event);" />
  35.     <mx:ApplicationControlBar dock="true">
  36.         <mx:ComboBox id="comboBox"
  37.                 prompt="Please select a song..."
  38.                 dataProvider="{playlist.song}"
  39.                 labelField="@title"
  40.                 change="comboBox_change(event);" />
  41.     </mx:ApplicationControlBar>
  42.     <mx:TextArea id="textArea"
  43.             editable="false"
  44.             width="100%"
  45.             height="100%" />
  46.     <mx:LinkButton id="linkButton"
  47.             label="All songs copyright Nine Inch Nails (2008)"
  48.             click="navigateToURL(new URLRequest(NIN_URL), '_blank');" />
  49. </mx:Application>
下面是歌曲List的XML文件:
Download: playlist.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- http://blog.flexexamples.com/2008/03/05/displaying-a-dynamically-loaded-mp3-files-id3-information-in-flex-using-the-soundeffect-class/ -->
  3. <playlist>
  4.     <song title="Track 1" source="assets/01 Ghosts I.mp3" />
  5.     <song title="Track 2" source="assets/02 Ghosts I.mp3" />
  6.     <song title="Track 3" source="assets/03 Ghosts I.mp3" />
  7.     <song title="Track 4" source="assets/04 Ghosts I.mp3" />
  8.     <song title="Track 5" source="assets/05 Ghosts I.mp3" />
  9.     <song title="Track 6" source="assets/06 Ghosts I.mp3" />
  10.     <song title="Track 7" source="assets/07 Ghosts I.mp3" />
  11.     <song title="Track 8" source="assets/08 Ghosts I.mp3" />
  12.     <song title="Track 9" source="assets/09 Ghosts I.mp3" />
  13. </playlist>
到 这里直接察看源代码,下面是执行Demo。

你可能感兴趣的:(职场,休闲)