0 0

我在做flex3 ria mp3 播放器时,总只能播放一个文件5

代码 mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
<!--设定全局样式-->
<mx:Style>
global{
fontSize:12pt;
}
</mx:Style>
<mx:Script>
<![CDATA[
    //引入需要的包
import mx.controls.Alert;
import flash.media.Sound;
        import flash.media.SoundChannel;
        import flash.media.SoundTransform;
        //声明用于Mp3播放的声音类
private var mp3_sound:Sound=new Sound();
private var mp3_request:URLRequest;
private var mp3_channel:SoundChannel;
//初始化函数
private function init():void{
//设定树形目录的根节点
fileTree.directory=FileSystemTree.COMPUTER;
//设定数据表格的根节点
fileDataGrid.directory=FileSystemTree.COMPUTER;
//只显示mp3文件
fileDataGrid.extensions=new Array(["mp3"]);
            //设定文件数据表格的表头显示
fileDataGrid.nameColumn.headerText="名称";
fileDataGrid.sizeColumn.headerText="大小";
fileDataGrid.typeColumn.headerText="类型";
fileDataGrid.creationDateColumn.headerText="创建日期";
fileDataGrid.modificationDateColumn.headerText="修改日期";
}
//播放mp3
private function playMusic():void{

//得到选中的文件
var curFile:File=File(fileDataGrid.selectedItem);
//显示播放文件的名称
curDisplay.text="当前播放:"+curFile.name;
//设定请求
mp3_request=new URLRequest(curFile.url);
//加载Mp3文件
mp3_sound.load(mp3_request);
//进行播放
mp3_channel = mp3_sound.play();
}
private function PlayUrl():void{
//设定请求
mp3_request=new URLRequest(url_txt.text);
//加载Mp3文件
//显示播放文件的名称
curDisplay.text="当前播放:"+url_txt.text;
mp3_sound.load(mp3_request);
//进行播放
mp3_sound.play();
}
]]>
</mx:Script>
<mx:HBox width="100%" height="100%" horizontalCenter="0" verticalCenter="0">
<!--设定Tree只显示文件夹。当点选得Tree文件夹发生改变时,数据表格显示当前选中的文件夹当中的内容-->
<mx:FileSystemTree id="fileTree"
            width="30%" height="100%"
            enumerationMode="directoriesOnly"
            change="fileDataGrid.directory = File(fileTree.selectedItem);"/>  
<mx:VDividedBox width="70%" height="100%">
<mx:Text id="curDisplay" text="当前播放:"/>
<mx:HBox width="100%">
<mx:Label text="URL"/>
<mx:TextInput id="url_txt" width="50%"/>
<mx:Button label="播放" click="PlayUrl()"/>
</mx:HBox>
        <mx:FileSystemDataGrid id="fileDataGrid"
            width="100%" height="100%" itemClick="playMusic()"/>
</mx:VDividedBox>
</mx:HBox>
</mx:WindowedApplication>
2008年11月28日 14:33
目前还没有答案

相关推荐

Global site tag (gtag.js) - Google Analytics