任何麦克风动作脚本代码,指示麦克风上有活动时的进度条
答案 0 :(得分:1)
这里有一些你可以使用的代码:
它使用图形API绘制音量指示
<?xml version="1.0" encoding="utf-8"?><mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
width="450"
height="450"
creationComplete="creationComplete_Handler()">
<mx:Script>
<![CDATA[
import flash.media.Microphone;
import flash.events.ActivityEvent;
import flash.events.Event;
import flash.events.StatusEvent;
private var _mic:Microphone;
private function creationComplete_Handler():void
{
_mic = Microphone.getMicrophone();
_mic.setLoopBack(true);
_mic.addEventListener(Event.ACTIVATE, mic_ActivateEventHandler);
_mic.addEventListener(StatusEvent.STATUS, mic_StatusEventHandler);
_mic.addEventListener(ActivityEvent.ACTIVITY, mic_ActivityEventHandler);
}
private function mic_ActivateEventHandler(e:Event):void
{
lblStatus.text = "mic active!";
}
private function mic_StatusEventHandler(e:StatusEvent):void
{
trace("ststus event: " + e.toString());
}
private function mic_ActivityEventHandler(e:ActivityEvent):void
{
trace("Activity Event");
addEventListener(Event.ENTER_FRAME, mic_EnterFrame_EventHandler);
}
private function mic_EnterFrame_EventHandler(e:Event):void
{
lblMicLevel.text = "Mic Level :"+_mic.activityLevel.toString();
micLevelCanvas.graphics.clear();
micLevelCanvas.graphics.beginFill(000000, 1);
micLevelCanvas.graphics.drawRect(0, 0, (_mic.activityLevel * 2), 20);
micLevelCanvas.graphics.endFill();
}
]]>
</mx:Script>
<mx:Label x="10" y="10" id="lblStatus"/>
<mx:Canvas x="10" y="36" width="200" height="20" id="micLevelCanvas" />
<mx:Label x="10" y="64" id="lblMicLevel"/></mx:Application>