Use Microphone : Microphone « Development « Flash / Flex / ActionScript






Use Microphone

 
package
{

    import flash.display.Sprite;
    import flash.events.ActivityEvent;
    import flash.events.Event;
    import flash.events.StatusEvent;
    import flash.media.Microphone;
    public class Main extends Sprite
    {

        public var mic:Microphone = Microphone.getMicrophone();
        public var level:Sprite;

        public function Main()
        {
            mic.setLoopBack(true);
            mic.addEventListener(ActivityEvent.ACTIVITY, activity);
            mic.addEventListener(StatusEvent.STATUS, status);
            mic.addEventListener(Event.ACTIVATE, active);
            addEventListener(Event.ENTER_FRAME, showMicLevel);
            level = new Sprite();
            addChild(level);
            level.y = 200;
            level.x = 100;
        }

        private function active(event:Event):void
        {
            trace("active");
        }

        private function status(event:StatusEvent):void
        {
            trace("status");
        }

        private function activity(event:ActivityEvent):void
        {
            trace("activity");
        }

        private function showMicLevel(event:Event):void
        {
            trace(mic.gain
                    + " " + mic.activityLevel
                    + " " + mic.silenceLevel
                    + " " + mic.index
                    + " " + mic.rate);
            level.graphics.beginFill(0xccccff, 1);
            level.graphics.drawRect(0, 0, (mic.activityLevel * 3), 100);
            level.graphics.endFill();
        }
    }
}

        








Related examples in the same category

1.Media Servers
2.Introducing the Microphone