FlashMediaServer経由でビデオチャット
C:\Program Files\Macromedia\Flash Media Server 2\applications配下に、”flex_videoconference”フォルダを作成
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"> <mx:Script> <![CDATA[
import mx.controls.Alert; import flash.media.Camera; public var cam:Camera; private var ncPub:NetConnection = new NetConnection(); private var nsPub:NetStream; public function initCamera():void { cam = Camera.getCamera(); pubVid.attachCamera(cam); ncPub.objectEncoding = ObjectEncoding.AMF0; ncPub.addEventListener(AsyncErrorEvent.ASYNC_ERROR, errorEventHandler); ncPub.addEventListener(IOErrorEvent.IO_ERROR, errorEventHandler); ncPub.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorEventHandler); ncPub.addEventListener(NetStatusEvent.NET_STATUS, ncPubHandler); ncPub.connect("rtmp://localhost/flex_videoconference"); } private function ncPubHandler(e:Event):void { //trace(e.type); if(e is NetStatusEvent) { trace(NetStatusEvent(e).info.code); if(NetStatusEvent(e).info.code == "NetConnection.Connect.Success") { nsPub = new NetStream(ncPub); nsPub.attachCamera(cam); nsPub.publish("mystream","live"); srvVid.source = "rtmp://localhost/flex_videoconference/mystream"; } } } private function errorEventHandler(e:Event):void { var ls:String = "\n"; var msg:String = ""; if(e is AsyncErrorEvent) { msg = AsyncErrorEvent(e).error + ls + AsyncErrorEvent(e).text; } if(e is IOErrorEvent) { msg = IOErrorEvent(e).text; } if(e is SecurityErrorEvent) { msg = SecurityErrorEvent(e).text; } Alert.show(msg, e.type); }
]]> </mx:Script> <mx:HBox id="hbx"> <mx:VideoDisplay id="pubVid" width="320" height="240" creationComplete="initCamera();"/> <mx:VideoDisplay id="srvVid" autoBandWidthDetection="false" live="true" maintainAspectRatio="false" width="320" height="240"/> </mx:HBox> </mx:Application>