Skip to content
Dec 4 / Peter deHaan

Detecting the microphone in Flash using ActionScript 3.0

The following example shows how you can request access to the user’s microphone using the static Microphone.getMicrophone() method and listening for the status event.

Full code after the jump.

// ActionScript 3.0
var mic:Microphone = Microphone.getMicrophone();
mic.setLoopBack();
mic.addEventListener(StatusEvent.STATUS, mic_status);
 
var tf:TextField = new TextField();
tf.autoSize = TextFieldAutoSize.LEFT;
tf.text = "Detecting microphone...";
addChild(tf);
 
function mic_status(evt:StatusEvent):void {
    tf.text = "Microphone is muted?: " + mic.muted;
    switch (evt.code) {
        case "Microphone.Unmuted":
            tf.appendText("\n" + "Microphone access was allowed.");
            break;
        case "Microphone.Muted":
            tf.appendText("\n" + "Microphone access was denied.");
            break;
    }
}

6 Comments

leave a comment
  1. Tamer / Jan 13 2009

    Hi,
    We were looking for a way to capture the mic audio data and save it to mp3
    Will this really need a flash communication server!??!

    Please advise
    Thanks
    Tamer

  2. Echo / Feb 24 2009

    hi,
    thanks for useful example you placed here. i am too excited in capturing sound and saving it to whatever format for now. any Idea ?

    Thanks Again
    Echo

  3. Jim / Mar 22 2009

    I want to know microphone recording too.
    Must we need FMS?
    Why cant it be saved to somewhere upon finishing recording?

  4. houdini / Jun 4 2009

    Hi there!

    Isn’t it possible to store recorded data in byte array?

    Greetings houdini

  5. sara / Jun 30 2009

    thank you this example help me in my work thanks_Egypt

  6. Anthony / Sep 25 2009

    Hi all,
    If your interested in saving the input to the file, your will need to store it in a byte array and then output the byte array data to a file of your choose with the right encoding of the file.

    Check out: http://theflashblog.com/?p=1426

    Thanks,
    Ant.

Leave a Comment