Created
April 5, 2011 00:44
-
-
Save tmaeda/902796 to your computer and use it in GitHub Desktop.
flashでマイクを使うテスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MicTest.as | |
package { | |
import flash.display.*; | |
import flash.events.*; | |
import flash.media.*; | |
import flash.net.*; | |
import flash.system.Security; | |
import flash.system.SecurityPanel; | |
public class MicTest extends Sprite { | |
private var _mic:Microphone; | |
private var _circle:Sprite; | |
public function MicTest() { | |
log("foo"); | |
_mic = Microphone.getMicrophone(); | |
if (_mic != null) { | |
_mic.rate = 44; | |
_mic.setSilenceLevel(10); | |
_mic.setLoopBack(true); | |
_mic.setUseEchoSuppression(true); | |
_mic.addEventListener(ActivityEvent.ACTIVITY, activityHandler); | |
_mic.addEventListener(StatusEvent.STATUS, statusHandler); | |
// var soundTransform:SoundTransform = _mic.soundTransform; | |
// soundTransform.volume = 0; | |
// _mic.soundTransform = soundTransform; | |
this.addEventListener(Event.ENTER_FRAME, onEnterFrame); | |
} else { | |
log("bar"); | |
} | |
_circle = new Sprite(); | |
this.addChild(_circle); | |
} | |
private function activityHandler(event:ActivityEvent):void { | |
log("activityHandler: " + event); | |
} | |
private function statusHandler(event:StatusEvent):void { | |
log("statusHandler: " + event); | |
} | |
public function onEnterFrame(event:Event):void | |
{ | |
// log(_mic.activityLevel); | |
_circle.graphics.clear(); | |
var lineWeight:Number = 3; | |
var rate:Number = 2; | |
var level:Number = _mic.activityLevel * rate; | |
var center:Number = 100 * rate; | |
if (level > 90) { | |
_circle.graphics.lineStyle(lineWeight, 0xff0000); | |
} else if (level > 50) { | |
_circle.graphics.lineStyle(lineWeight, 0xffff00); | |
} else { | |
_circle.graphics.lineStyle(lineWeight, 0x00ff00); | |
} | |
// _circle.scaleX = _circle.scaleY = _mic.activityLevel * 0.1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment