命运践踏win

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

利用组件做的音乐播放器:(文件里有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  命运践踏win  阅读(161)  评论(0编辑  收藏  举报