Access a User's Microphone and Create a Sound Display : Microphone « Development « Flex






Access a User's Microphone and Create a Sound Display

Access a User's Microphone and Create a Sound Display
           

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
    <mx:VBox width="400" height="300" creationComplete="createMic()">
    
    <mx:Script>
        
        import flash.media.Microphone;
        import flash.events.ActivityEvent;
        import flash.events.Event;
        import mx.controls.Alert;
        import flash.events.StatusEvent;
    
          public var mic:Microphone;
    
          public function createMic():void
          {
            mic = Microphone.getMicrophone();
            mic.setLoopBack(true);
            mic.addEventListener(ActivityEvent.ACTIVITY, activity);
            mic.addEventListener(StatusEvent.STATUS, status);
            mic.addEventListener(Event.ACTIVATE, active);
          }
    
          private function active(event:Event):void
          {
            Alert.show('active');
          }
    
          private function status(event:StatusEvent):void
          {
            Alert.show("status");
          }
    
          private function activity(event:ActivityEvent):void
          {
            addEventListener(Event.ENTER_FRAME, showMicLevel);
          }
    
          private function showMicLevel(event:Event):void
          {
            Alert.show(mic.gain+" "+mic.activityLevel+" "+mic.silenceLevel+" "+mic.rate);
            level.graphics.clear();
            level.graphics.beginFill(0xccccff, 1);
            level.graphics.drawRect(0, 0, (mic.activityLevel * 30), 100);
            level.graphics.endFill();
          }
    
      
    </mx:Script>
    <mx:Canvas width="300" height="50" id="level"/>
    </mx:VBox>
</mx:Application>
    

   
    
    
    
    
    
    
    
    
    
    
  








Related examples in the same category