Flash / Flex / ActionScript/Development/Microphone — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 09:19, 26 мая 2010

Introducing the Microphone

 
package
{
    import flash.display.Sprite;
    import flash.events.*;
    import flash.media.Microphone;
    import flash.system.Security;
    public class Main extends Sprite
    {
        public function Main ()
        {
            var mic:Microphone = Microphone.getMicrophone();
            Security.showSettings("2");
            mic.setLoopBack(true);
            if (mic != null)
            {
                mic.setUseEchoSuppression(true);
                mic.addEventListener(ActivityEvent.ACTIVITY, activityHandler);
                mic.addEventListener(StatusEvent.STATUS, statusHandler);
            }
        }
        private function activityHandler(event:ActivityEvent):void
        {
            trace("activityHandler: " + event);
        }
        private function statusHandler(event:StatusEvent):void
        {
            trace("statusHandler: " + event);
        }
    }
}



Media Servers

 
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 = new 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);
            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();
        }
    }
}



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();
        }
    }
}