http://www.karaokeboho.com/index2.html
this is the site im currenlty developing and the visualizer runs as a background
sometimes gets an error and wouldnt continue playing!!
here is the code for the visualizer.
//Visualizer.as
package
{
import flash.display.*;
import flash.media.*; // need for sound, soundmixer
import flash.net.*; // need for urlrequest
import flash.events.*;
import flash.utils.*; // need for bytearray
import flash.filters.*;
public class Visualizer extends Sprite
{
private var ba:ByteArray = new ByteArray();
private var lineThickness:Number;
private var lineColor:Number;
private var circleSize:Number;
private var timer:Timer;
private var type:String;
private var scaleOnBeat:Number = 1.2;
private var reactToBeat:Number = 50;
private var added:Boolean;
function Visualizer(param:Object) // param : color, size, thinkness, blur
{
lineColor = param.color;
lineThickness = param.thickness;
circleSize = param.size;
if (param.blur != null){
this.filters = [new BlurFilter(param.blur,param.blur, BitmapFilterQuality.HIGH)];
}
this.addEventListener(Event.ADDED_TO_STAGE, init);
this.addEventListener(Event.REMOVED_FROM_STAGE, removed);
}
private function init(e:Event):void
{
added = true;
}
private function removed(e:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, init);
this.removeEventListener(Event.REMOVED_FROM_STAGE, removed);
timer.removeEventListener(TimerEvent.TIMER, processBar);
timer.removeEventListener(TimerEvent.TIMER, processCircle);
}
private function processCircle(e:Event):void
{
if (added){
SoundMixer.computeSpectrum(ba, false, 0);
this.graphics.clear();
this.graphics.moveTo(0, -circleSize);
this.graphics.lineStyle(lineThickness,lineColor);
var vol:Number = 0;
for (var i:uint = 0; i <512; i += 1){
var lev:Number = ba.readFloat();
vol += lev;
var a:uint = i;
if (i < 256) a += 256;
if (i == 256) graphics.moveTo(0, -circleSize);
graphics.lineTo(-Math.sin(i/256*Math.PI) * circleSize * (lev+1),
Math.cos(a/256*Math.PI) * circleSize * (lev+1));
}
if (vol>reactToBeat){
this.scaleX = this.scaleY = scaleOnBeat;
} else {
this.scaleX = this.scaleY = 1;
}
}
}
private function processBar(e:Event):void
{
if (added){
SoundMixer.computeSpectrum(ba, false, 0);
this.graphics.clear();
this.graphics.lineStyle(lineThickness, lineColor);
this.graphics.moveTo(0,0);
var vol:Number = 0;
for (var i:uint=0; i <512; i+=1){
var lev:Number = ba.readFloat();
vol += lev;
var n:Number = (lev * 100);
graphics.lineTo(i*1.5, n);
}
if (vol>reactToBeat){
this.scaleY = scaleOnBeat;
} else {
this.scaleY = 1;
}
}
}
public function changeColor(color:Number):void
{
lineColor = color;
}
public function playBar():void
{
type = "bar";
try {timer.reset();} catch(e:Error){}
timer = null;
timer = new Timer(50);
timer.addEventListener(TimerEvent.TIMER, processBar);
timer.start();
}
public function playCircle():void
{
type = "circle";
try {timer.reset();} catch(e:Error){}
timer = null;
timer = new Timer(50);
timer.addEventListener(TimerEvent.TIMER, processCircle);
timer.start();
}
public function getName():String
{
return type;
}
public function hide():void
{
try {timer.removeEventListener(TimerEvent.TIMER, processBar);} catch(e:Error){}
try {timer.removeEventListener(TimerEvent.TIMER, processCircle);} catch(e:Error){}
this.graphics.clear();
}
}
}
2030End of file was encountered.
this was the error i got last time i checked it.