Flash: Actionscript 3 Compute-Spectrum
Von Martin Bommeli | Keine | 11.01.2008
Ende 2006 habe ich für ein SFUG Meeting einen kleinen Equalizer entwickelt. Diesen habe ich wiedermal hervorgenommen und etwas erweitert.
bitte Flash Player installieren!
mp3 File: cgibbsallstateunion.mp3
Hier ein Codeauszug:
SWFObject Einbindung
var so = new SWFObject("soundvisualizer.swf","swfid","500","150","9"); so.addVariable("trackname","All State union"); so.addVariable("trackartist","C. Gibbs"); so.addVariable("autostart","0"); so.addVariable("file","test.mp3"); so.write("mp3_player");
AS3
/************************************************** spectrum_show() - BytesArray auslesen und darstellen ****************************************************/ private function spectrum_show(e:Event):void{ var lineY:Number; var gMC:MovieClip; var ba:ByteArray = new ByteArray(); var bytesL:Number = snd.bytesLoaded; var bytesT:Number = snd.bytesTotal; var bytesP:Number = bytesL/bytesT*100; txt1.autoSize = TextFieldAutoSize.RIGHT; txt1.text = Math.round(bytesP)+"% geladen"; if (bytesP == 100) { txt1.text = ""; } txt1.x = stage.stageWidth-txt1.width; gMC = spectrum_mc; gMC.graphics.clear(); gMC.grundlinie_mc.width = gMC.fade_mc.width = stage.stageWidth; lineY = gMC.grundlinie_mc.y; SoundMixer.computeSpectrum(ba,true,1); var i:uint; for (i=0; i<512; i+=1) { var a:Number = ba.readFloat(); var num:Number = a*lineY; var lineW:Number = 5; var lineX:Number; lineX = i*stage.stageWidth/512; //Balken nach oben gMC.graphics.beginFill(0x4FA6FF,1); gMC.graphics.drawRect(lineX,lineY,lineW,-num/2); //Balken nach unten gMC.graphics.beginFill(0x4FA6FF,2); gMC.graphics.drawRect(lineX,lineY,lineW,num/2); } }