·您当前的位置:首页 > 技术教程 > Rtmp技术 >

[FMS]FMS实现视频聊天的代码示例(含发布端和接收端)

时间:2012-10-23 23:12cnblogs.com
[FMS]FMS实现视频聊天的代码示例(含发布端和接收端) FMS视频,fms发布端,fms接收端

发布端(Publish.mxml)

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
  3.                xmlns:s="library://ns.adobe.com/flex/spark" 
  4.                xmlns:mx="library://ns.adobe.com/flex/mx" initialize="init()"> 
  5.     <s:layout> 
  6.         <s:BasicLayout/> 
  7.     </s:layout> 
  8.     <fx:Declarations> 
  9.         <!-- 将非可视元素(例如服务、值对象)放在此处 --> 
  10.     </fx:Declarations> 
  11.     <fx:Script> 
  12.         <![CDATA[ 
  13.             import mx.core.UIComponent; 
  14.             private var nc:NetConnection; 
  15.             private var mic:Microphone; 
  16.             private var cam:Camera; 
  17.             private function init():void 
  18.             { 
  19.                 //加载自己的摄像头 
  20.                 mic = Microphone.getMicrophone(); 
  21.                 cam = Camera.getCamera(); 
  22.                 var video:Video = new Video(); 
  23.                 video.attachCamera(cam); 
  24.                 var uiBox:UIComponent = new UIComponent(); 
  25.                 uiBox.addChild(video); 
  26.                 this.addElement(uiBox); 
  27.                 nc = new NetConnection(); 
  28.                 nc.addEventListener(NetStatusEvent.NET_STATUS,onNetStatus); 
  29.                 nc.connect("rtmp://192.168.1.16/virtualShow"); 
  30.                 nc.client = this; 
  31.             } 
  32.             private function onNetStatus(evt:NetStatusEvent):void 
  33.             { 
  34.                 trace(evt.info.code); 
  35.                 if(evt.info.code=="NetConnection.Connect.Success") 
  36.                 { 
  37.                     var ns:NetStream = new NetStream(nc); 
  38.                     ns.addEventListener(NetStatusEvent.NET_STATUS,onNetStatus); 
  39.                     ns.attachAudio(mic); 
  40.                     ns.attachCamera(cam); 
  41.                     ns.client = this; 
  42.                     ns.publish("hxw","live"); 
  43.                 } 
  44.             } 
  45.             public function onBWDone():void 
  46.             { 
  47.             } 
  48.         ]]> 
  49.     </fx:Script> 
  50. </s:Application> 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器