A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Mic Input totally crashes flash

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    1

    Mic Input totally crashes flash

    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!

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You shouldn't nest functions. You have defined onDelay inside onMicActivity. So each time onMicActivity executes you create a new timer and a new listener function on that new timer. You should probably move both the timer and onDelay outside onMicActivity to avoid creating several identical copies.

    You should also use a repeating Timer and a TimerEvent listener rather than using setInterval, though that is mostly a matter of doing things in AS3 style rather than a performance issue.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center