以下是用flex制作简单mp3的源码。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
width="400" height="110" layout="vertical"
horizontalAlign="center" verticalAlign="center"
>
<mx:Script>
<![CDATA[
import mx.core.SoundAsset;
import flash.media.*;
<!-- 指定mp3的位置-->
[Embed(source="song/20071028053735_429833834.mp3")]
[Bindable]
public var Song:Class;
public var mySong:SoundAsset = new Song() as SoundAsset;
public var channel:SoundChannel;
// 播放
public function playSound():void
{
stopSound();
// 循环播放
channel = mySong.play(0,int.MAX_VALUE);
}
// 停止
public function stopSound():void
{
if ( channel != null ) channel.stop();
}
]]>
</mx:Script>
<mx:HBox>
<mx:Button label="play" click="playSound();"/>
<mx:Button label="stop" click="stopSound();"/>
</mx:HBox
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
width="400" height="110" layout="vertical"
horizontalAlign="center" verticalAlign="center"
>
<mx:Script>
<![CDATA[
import mx.core.SoundAsset;
import flash.media.*;
<!-- 指定mp3的位置-->
[Embed(source="song/20071028053735_429833834.mp3")]
[Bindable]
public var Song:Class;
public var mySong:SoundAsset = new Song() as SoundAsset;
public var channel:SoundChannel;
// 播放
public function playSound():void
{
stopSound();
// 循环播放
channel = mySong.play(0,int.MAX_VALUE);
}
// 停止
public function stopSound():void
{
if ( channel != null ) channel.stop();
}
]]>
</mx:Script>
<mx:HBox>
<mx:Button label="play" click="playSound();"/>
<mx:Button label="stop" click="stopSound();"/>
</mx:HBox
</mx:Application>