您的位置:首页 > 其它

用flex制作最简单的mp3播放器

2008-01-22 10:09 211 查看
以下是制作简单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.*;

[Embed(source="song.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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: