flash on 2010-1-17
import setting.setMed;
import setting.setNet;
/**
* Copyright venthels ( http://wonderfl.net/user/venthels )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/up0c
*/
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
//import setting.setMed;
//import setting.setNet;
public class testMic3 extends Sprite {
//private var uri:String = 'rtmp://localhost/test';
private var Med:setMed = new setMed();
private var Net:setNet = new setNet(uri);
private var camSp:Sprite = new Sprite();
private var nsAr:Array = new Array();
private var timer:Array = new Array();
private var countFlg:Boolean = false;
private var count:int = 0;
public function testMic3():void {
Med.setMic();
stage.addEventListener(MouseEvent.MOUSE_DOWN, MD);
stage.addEventListener(MouseEvent.MOUSE_UP, playFunc);
stage.addEventListener(Event.ENTER_FRAME, loopPlay);
stage.addEventListener(Event.ENTER_FRAME, loop);
//timer.push(new Timer(2000));
//timer[timer.length-1].addEventListener(TimerEvent.TIMER, testFunc);
//timer[timer.length-1].start();
}
private function loop(e:Event):void {
try {
for(var i:int=0; i<timer.length; i++) {
if(!timer[i].running) {
trace("rePlay" + i);
timer[i].start();
nsAr[i].play("videoRec"+String(nsAr.length-1));
}
}
}
catch(e:Error) {
}
}
private function testFunc(e:TimerEvent):void {
//trace("rePlay");
for(var i:int=0; i<nsAr.length; i++) {
//nsAr[i].togglePause();
//nsAr[i].seek(0);
//nsAr[i].resume();
}
}
private function MD(e:MouseEvent):void {
trace("Rec" + nsAr.length);
nsAr.push(Net.setNs());
nsAr[nsAr.length-1].attachAudio(Med.mic);
nsAr[nsAr.length-1].publish("videoRec"+String(nsAr.length-1), "record");
}
private function playFunc(e:MouseEvent):void {
trace("play "+(nsAr.length-1));
trace("蜀咲函譎る俣 : "+nsAr[nsAr.length-1].time);
timer.push(new Timer((nsAr[nsAr.length-1].time)*1000));
timer[timer.length-1].repeatCount = 1;
//timer[timer.length-1].addEventListener(TimerEvent.TIMER, testFunc);
timer[timer.length-1].start();
nsAr[nsAr.length-1].play("videoRec"+String(nsAr.length-1));
}
private function loopPlay(e:Event):void {
for(var i:int=0; i<nsAr.length; i++) {
//nsAr[i].play("videoRec");
}
}
}
}
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.media.Microphone;
import flash.media.Camera;
import flash.media.Video;
import flash.events.ActivityEvent;
import flash.events.StatusEvent;
class setMed extends Sprite{
public var mic:Microphone = Microphone.getMicrophone();
public var cam:Camera = Camera.getCamera();
public var vid:Video;
public function setMed():void {
}
public function setMic():void {
//trace('\n');
//trace("device names: " + deviceArray);
mic.gain = 60;
mic.rate = 11;
//mic.setUseEchoSuppression(true);
//mic.setLoopBack(true);
mic.setSilenceLevel(1, 10);
trace(".........Mic..........");
var micDetails:String = "Sound input device name: " + mic.name + '\n';
micDetails += "ID: " + mic.index + '\n';
micDetails += "Gain: " + mic.gain + '\n';
micDetails += "Rate: " + mic.rate + " kHz" + '\n';
micDetails += "Muted: " + mic.muted + '\n';
micDetails += "Silence level: " + mic.silenceLevel + '\n';
micDetails += "Silence timeout: " + mic.silenceTimeout + '\n';
micDetails += "Echo suppression: " + mic.useEchoSuppression + '\n';
trace(micDetails);
mic.addEventListener(ActivityEvent.ACTIVITY, onMicActivity);
mic.addEventListener(StatusEvent.STATUS, onMicStatus);
}
public function onMicStatus(event:StatusEvent):void {
trace("status: level=" + event.level + ", code=" + event.code);
}
public function onMicActivity(event:ActivityEvent):void {
//trace("Level : " + mic.activityLevel);
//if(mic.activityLevel == 0)
//stopRec();
//else
//startRec();
}
public function setCam(_sp:Sprite):void {
//var mySp:Sprite = _sp;
if(cam != null) {
vid = new Video(320,240);
vid.attachCamera(cam);
_sp.addChild(vid);
}
else {
trace("cam_error");
}
trace(".............Camera............");
var camDetails:String = "";
camDetails += "camera states" + '\n';
trace(camDetails);
}
}
import flash.events.AsyncErrorEvent;
import flash.events.IOErrorEvent;
import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.ObjectEncoding;
class setNet {
public var nc:NetConnection;
public var ns:NetStream;
public var uri:String;
public var connectFlg:Boolean;
public function setNet(_uri:String):void {
//uri = _uri;
setNc(_uri);
}
public function setNc(uri:String):Boolean {
nc = new NetConnection();
nc.objectEncoding=ObjectEncoding.AMF0;//←コレ重要
//nc.client = new CustomClient();
//nc.connect('rtmp://id2.is.meisei-u.ac.jp/soundScape');
nc.connect(uri);
trace("........net connection.......");
trace("client : "+nc.client);
trace("uri : "+nc.uri + "\n");
nc.addEventListener(NetStatusEvent.NET_STATUS, onNcNetStatusEvent);
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onNcAsyncErrorEvent);
nc.addEventListener(IOErrorEvent.IO_ERROR, onNcIOErrorEvent);
return nc.connected;
}
public function onNcNetStatusEvent(evt:NetStatusEvent):void {
switch(evt.info.code) {
case "NetConnection.Connect.Success":
trace("アプリケーションへの接続が成功しました。");
//clientID = nc.clientID;
connectFlg = true;
break;
case "NetConnection.Connect.Failed":
trace("アプリケーションへの接続が失敗しました。");
break;
case "NetConnection.Connect.Rejected":
trace("アプリケーションに接続する権限がありません。");
break;
case "NetConnection.Connect.Closed":
trace("アプリケーションへの接続が無事解除されました。");
break;
case "NetStream.Play.Complete":
trace ("再生の完了");
break;
case "NetConnection.Connect.InvalidApp":
trace("アプリケーション名が無効です。");
default:
trace(evt.info.code);
break;
}
}
public function onNcAsyncErrorEvent(evt:AsyncErrorEvent):void {
trace("AsyncErrorEvent エラー");
trace(evt.toString());
}
public function onNcIOErrorEvent(evt:IOErrorEvent):void {
trace("IOErrorEvent エラー");
}
public function setNs():NetStream {
trace("..........make net stream..........");
try {
ns = new NetStream(nc);
var client:Object = new Object();
//client.onMetaData = onMetaData;
ns.client = client;
trace("Success set net steam");
return ns;
}
catch(e:Error) {
trace("error set net stream");
}
return null;
}
}