I am working on a project that plays a sound when the mic input does not detect any sound.
It works perfectly only one problem.
When I close the preview in flash I get no error but flash cs5 totally crashes.
Anybody got a clue on why this happens?
I suspect the computer cash fills up with the information about the mic input and can't handle it anymore so crashes,
but I am not sure and don't know how I could fix this. I do know when the animation_mc.play(); is removed it does not crash.
(In my animation_mc are the audio files that should be played when the mic does not detect an input.)
Here is my main code
Actionscript Code:
var verdergaan = false;
var mic:Microphone = Microphone.getMicrophone();
mic.gain = 50;
mic.rate = 8;
mic.setLoopBack(true);
mic.soundTransform = new SoundTransform(0, 0);
mic.setSilenceLevel(20, 2000);
mic.addEventListener(ActivityEvent.ACTIVITY, this.onMicActivity);
mic.addEventListener(StatusEvent.STATUS, this.onMicStatus);
var micDetails:String = "Sound input device name: " + mic.name + '\n';
micDetails += "Gain: " + mic.gain + '\n';
micDetails += "Rate: " + mic.rate + " kHz" + '\n';
micDetails += "Muted: " + mic.muted + '\n';
micDetails += "Silence level: " + mic.silenceLevel + '\n';
micDetails += "Silence timeout: " + mic.silenceTimeout + '\n';
micDetails += "Echo suppression: " + mic.useEchoSuppression + '\n';
function onMicActivity(evt:ActivityEvent):void {
trace("activating=" + evt.activating + ", activityLevel=" + mic.activityLevel);
if(mic.activityLevel>20){
//verdergaan = true;
//trace(verdergaan);
animation_mc.stop();
trace("je hebt net gepraat");
var t:Timer = new Timer(1000);
t.addEventListener(TimerEvent.TIMER, onDelay);
t.start()
function onDelay(te:Event):void {
if(mic.activityLevel<20){
animation_mc.play();
trace("je hebt net gepraat1");
t.stop();
}
}
}
//verdergaan = true;
}
function onMicStatus(evt:StatusEvent):void {
trace("status: level=" + evt.level + ", code=" + evt.code);
}
function luister(){
if (verdergaan == true){
animation_mc.play();
}
}
setInterval(luister,3000);
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
function myKeyDown(e:KeyboardEvent):void{
if (e.keyCode == Keyboard.SPACE){
animation_mc.play();
}
}
Really hope someone can help me!