Record Mic using SampleDataEvent works only on some computers.
I made a swf that records your mic and allows you to play it back. I load the soundBytes into a float and play the float back. It works fine on the computer I developed it on (in IE, Chrome and Firefox) . It does not work on my second laptop. And a few people in some forums have said it is not working either.
Here is the file. http://www.buttonbeats.com/images/MicCapture.html
Here is the code. Do I need certain plugins besides the flash player?
micRec.addEventListener(MouseEvent.CLICK,recordMic);
function recordMic(event:MouseEvent){
micRec.x = -250;
stopRecord.x = 0;
const DELAY_LENGTH:int = 4000;
var mic:Microphone = Microphone.getMicrophone();
mic.setSilenceLevel(0, DELAY_LENGTH);
mic.gain = 80;
mic.rate = 40;
mic.addEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
stopRecord.addEventListener(MouseEvent.CLICK,SREC);
var soundBytes:ByteArray = new ByteArray();
function micSampleDataHandler(event:SampleDataEvent):void
{
while(event.data.bytesAvailable)
{
var sample:Number = event.data.readFloat();
soundBytes.writeFloat(sample);
}
}
function SREC(event:MouseEvent):void
{
stopRecord.x = -250;
mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
soundBytes.position = 0;
var sound:Sound = new Sound();
sound.addEventListener(SampleDataEvent.SAMPLE_DATA, playbackSampleHandler);
soundPlay.addEventListener(MouseEvent.CLICK,SP1);
function SP1(event:MouseEvent){
soundBytes.position = 0;
sound.play();
}
}
function playbackSampleHandler(event:SampleDataEvent):void
{
for (var i:int = 0; i < 8192 && soundBytes.bytesAvailable > 0; i++)
{
var sample:Number = soundBytes.readFloat();
event.data.writeFloat(sample);
event.data.writeFloat(sample);
}
}
}