博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
音乐播放器…
阅读量:5008 次
发布时间:2019-06-12

本文共 6879 字,大约阅读时间需要 22 分钟。

利用组件做的音乐播放器:(文件里有swf文件…不过歌曲需要匹配……)

import flash.media.Sound;import flash.net.URLRequest;import flash.events.*;import flash.events.MouseEvent;import flash.media.SoundChannel;import fl.controls.*;import flash.media.SoundTransform;import fl.events.SliderEvent;import fl.data.*;import fl.events.*;import flash.display.Bitmap;import flash.media.SoundMixer;import flash.utils.ByteArray;import flash.display.Sprite;import flash.text.TextFormat;import fl.managers.StyleManager;[Embed(source = "1.jpg")]var img1:Class;[Embed(source = "2.jpg")]var img2:Class;[Embed(source = "3.jpg")]var img3:Class;[Embed(source = "4.jpg")]var img4:Class;[Embed(source = "5.jpg")]var img5:Class;[Embed(source = "6.jpg")]var img6:Class;[Embed(source = "7.jpg")]var img7:Class;[Embed(source = "8.jpg")]var img8:Class;var txtf:TextFormat = new TextFormat("宋体",13,0x325468);var yinbo:SoundMixer = new SoundMixer();var yinarr:ByteArray = new ByteArray();var mm:Number;var sp:Sprite = new Sprite(); var sound:Sound;var channel:SoundChannel = new SoundChannel();var sheng:SoundTransform = new SoundTransform();var bit:Bitmap;var bl:Number = 0;var bl2:Number = 0;var bl3:Number = 0;var ca:int = 0;var arr:Array = ["愿望.mp3","九公主.mp3","逃学书童.mp3","承认.mp3","没有什么不同.mp3","蝴蝶.mp3","多余的解释.mp3","第一首情歌.mp3"];var dp:DataProvider = new DataProvider();dp.addItem({ri:img1,label:arr[0]});dp.addItem({ri:img2,label:arr[1]});dp.addItem({ri:img3,label:arr[2]});dp.addItem({ri:img4,label:arr[3]});dp.addItem({ri:img5,label:arr[4]});dp.addItem({ri:img6,label:arr[5]});dp.addItem({ri:img7,label:arr[6]});dp.addItem({ri:img8,label:arr[7]});lieBaioList.dataProvider = dp;lieBaioList.sourceField = "ri";lieBaioList.height = 400;lieBaioList.rowHeight = 100;lieBaioList.columnWidth = 100;lieBaioList.direction = ScrollBarDirection.VERTICAL;lieBaioList.columnCount = 1;xianshiLabel.text = arr[ca];shangbtn.label = "《&";xiabtn.label = "》&";okbtn.label = ">>…";shengYin.tickInterval = 10;shengYin.maximum = 100;shengYin.value = 30;sheng.volume = shengYin.value * 0.01;channel.soundTransform = sheng;jindu.tickInterval = 10;jindu.maximum = 100;jindu.value = 0;StyleManager.setStyle("textFormat",txtf);this.addEventListener(Event.ENTER_FRAME,onyinbohandler);lieBaioList.addEventListener(ListEvent.ITEM_CLICK,onmyListClick);okbtn.addEventListener(MouseEvent.CLICK,onokBtn);shangbtn.addEventListener(MouseEvent.CLICK,onshangBtn);xiabtn.addEventListener(MouseEvent.CLICK,onxiaBtn);shengYin.addEventListener(SliderEvent.THUMB_DRAG,ontiaoShengYin);huantu();function huantu():void{    if (ca ==0)    {        bit = new img1();    }    if (ca ==1)    {        bit = new img2();    }    if (ca ==2)    {        bit = new img3();    }    if (ca ==3)    {        bit = new img4();    }    if (ca ==4)    {        bit = new img5();    }    if (ca ==5)    {        bit = new img6();    }    if (ca ==6)    {        bit = new img7();    }    if (ca ==7)    {        bit = new img8();    }    addChild(bit);    bit.x = 10;    bit.y = 10;    bit.height = 150;    bit.width = 220;}function onyinbohandler(e:Event):void{    mm = 0;    sp.graphics.clear();    //在舞台绘制,清空舞台绘制内容(因为音频频谱是随着时间的改变而不断变化的);    SoundMixer.computeSpectrum(yinarr,true,0);    //把音频数据化存入数组中.computeSpectrum(字节数组,模式,伸展因子);    for (var i=0; i<1100; i+=19)    {        mm = yinarr.readFloat();//把字节数组转化为32位单精度浮点数        var num:Number = mm * 180;//把字节数组放大        sp.graphics.lineStyle(2,0x131119,100);        //笔触 颜色 透明度Math.random() * 0xffffff + 0x000000;        //绘制图形的公式        sp.graphics.moveTo(10+i/7,320);        sp.graphics.lineTo(10+i/7,320-num/4);        addChild(sp);    }}function onkas(e:Event):void{    //trace(channel.position);    //trace(sound.length);    if (channel.position < sound.length)    {        stage.addEventListener(Event.ENTER_FRAME,onjiduHandler);    }}function onjiduHandler(e:Event):void{    bl2 = channel.position / sound.length * 100;    jindu.value = bl2;    jindu.addEventListener(SliderEvent.THUMB_DRAG,onJinDu);    if (bl2>=99)    {        trace(11111);        lieBaioList.scrollToIndex(ca);        ca++;        okbtn.label = "||…";        if (ca>7)        {            ca = 0;        }        if (okbtn.label == "||…")        {            okbtn.label = "||…";            channel.stop();            sound = new Sound();            sound.load(new URLRequest(arr[ca]));            channel = sound.play(bl);        }        else        {            bl = channel.position;            channel.stop();            okbtn.label = ">>…";        }        xianshiLabel.text = arr[ca];        huantu();    }}function onJinDu(e:SliderEvent):void{    bl3 = jindu.value / 100 * sound.length;    channel.stop();    channel = sound.play(bl3);}function onokBtn(e:MouseEvent):void{    if (okbtn.label == ">>…")    {        sound = new Sound();        sound.load(new URLRequest(arr[ca]));        sound.addEventListener(Event.COMPLETE,onkas);        channel = sound.play(bl);                okbtn.label = "||…";        lieBaioList.scrollToIndex(ca);    }    else    {        stage.removeEventListener(Event.ENTER_FRAME,onjiduHandler);        bl = channel.position;        channel.stop();        okbtn.label = ">>…";        lieBaioList.scrollToIndex(ca);    }    xianshiLabel.text = arr[ca];}function onshangBtn(e:MouseEvent):void{    bl3 = 0;    ca--;    //okbtn.label = "||…";    if (ca<0)    {        ca = 7;    }    if (okbtn.label == "||…")    {        bl = 0;        okbtn.label = "||…";        channel.stop();        sound = new Sound();        sound.load(new URLRequest(arr[ca]));        channel = sound.play(bl);            }    else    {        bl = channel.position;        channel.stop();        okbtn.label = ">>…";    }    xianshiLabel.text = arr[ca];    lieBaioList.scrollToIndex(ca);    huantu();}function onxiaBtn(e:MouseEvent):void{    bl3 = 0;    ca++;    //okbtn.label = "||…";    if (ca>7)    {        ca = 0;    }    if (okbtn.label == "||…")    {        bl = 0;        okbtn.label = "||…";        channel.stop();        sound = new Sound();        sound.load(new URLRequest(arr[ca]));        channel = sound.play(bl);            }    else    {        bl = channel.position;        channel.stop();        okbtn.label = ">>…";    }    xianshiLabel.text = arr[ca];    lieBaioList.scrollToIndex(ca);    huantu();}function ontiaoShengYin(e:SliderEvent):void{    sheng.volume = (shengYin.value)*0.01;    trace(shengYin.value);    channel.soundTransform = sheng;}function onmyListClick(e:ListEvent):void{    ca =(lieBaioList.selectedIndex)+1;    var bit:Bitmap = new e.item.ri();    addChild(bit);    bit.x = 10;    bit.y = 10;    bit.height = 150;    bit.width = 220;    channel.stop();    sound = new Sound();    sound.load(new URLRequest(e.item.label));    channel = sound.play(bl);    okbtn.label = "||…";    xianshiLabel.text = e.item.label;}
posted on
2012-10-29 21:07 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/win13/archive/2012/10/29/2745373.html

你可能感兴趣的文章
栅格数据AE
查看>>
开发笔记
查看>>
织梦DEDE多选项筛选_联动筛选功能的实现_二次开发
查看>>
SQL Server 排名函数 简单应用
查看>>
Could not find file "/var/www/default/bin\roslyn\csc.exe".
查看>>
关于软件工程的疑问
查看>>
iOS关于RunLoop和Timer
查看>>
SQL处理层次型数据的策略对比:Adjacency list vs. nested sets: MySQL【转载】
查看>>
已存在同名的数据库,或指定的文件无法打开或位于 UNC 共享目录中。
查看>>
MySQL的随机数函数rand()的使用技巧
查看>>
thymeleaf+bootstrap,onclick传参实现模态框中遇到的错误
查看>>
python字符串实战
查看>>
wyh的物品(二分)
查看>>
UNIX网络编程
查看>>
修改页面select <s:if------/>判断
查看>>
3. fooView rxjava + rxandroid + retrofit 安卓开发框架搭配 az kj
查看>>
项目启动及绩效评估
查看>>
SSM-Spring-08:Spring的静态代理初窥案例
查看>>
基于 Jenkins 快速搭建持续集成环境
查看>>
华为云.NET Core支持情况调查
查看>>