package {
import flash.display.Sprite;
import flash.utils.ByteArray;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.*;
import flash.net.URLRequest;
import flash.events.Event;
import flash.system.Security;
public class Main extends Sprite {
private var _channel:SoundChannel;
private var _graph:Sprite;
public function Main() {
Security.loadPolicyFile("http://rntsoft.com/crossdomain.xml");
var sound:Sound = new Sound();
sound.load(new URLRequest("http://rntsoft.com/Demo.mp3"), new SoundLoaderContext(1000, true));
_channel = sound.play();
_graph = new Sprite();
_graph.y = 200;
addChild(_graph);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function enterFrameHandler(event:Event):void {
var bytes:ByteArray = new ByteArray();
SoundMixer.computeSpectrum(bytes);
_graph.graphics.clear();
_graph.graphics.lineStyle(0, 0, 1);
var plotX:Number = 0;
for(var i:Number = 0; i < 256; i++) {
_graph.graphics.lineTo(plotX, bytes.readFloat() * stage.stageHeight / 2);
plotX += stage.stageWidth / 256;
}
}
}
}