Flex显示麦克风当前音量

Flex动态显示麦克风当前音量

效果:

Flex显示麦克风当前音量

代码:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="createMic()">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import flash.media.Microphone;
import flash.events.ActivityEvent;
import flash.events.Event;
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
{
trace(' active ');
} private function status(event:StatusEvent):void
{
trace("status");
} private function activity(event:ActivityEvent):void
{
trace("active ");
addEventListener(Event.ENTER_FRAME, showMicLevel);
} private function showMicLevel(event:Event):void
{
trace(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();
}
]]>
</fx:Script>
<mx:Canvas width="300" height="50" id="level"/>
</s:Application>
上一篇:python--str的几个方法


下一篇:TBitmapSurface.StretchFrom