Detecting the microphone in Flash using ActionScript 3.0

by Peter deHaan on December 4, 2008

in Microphone

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… read them below or add one }

1 Tamer 01.13.09 at 3:23 am

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 02.24.09 at 4:35 am

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 03.22.09 at 6:51 pm

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

4 houdini 06.04.09 at 11:51 am

Hi there!

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

Greetings houdini

5 sara 06.30.09 at 4:04 am

thank you this example help me in my work thanks_Egypt

6 Anthony 09.25.09 at 3:12 am

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

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: