FMS3.5 flash视频聊天室(远程共享,录制,验证,播放,加缓冲)

阅读更多

我采用的是在fms的applications文件夹下赋值live文件夹改名为videoChat

配置fms.ini增加程序路径

配置videoChat里Application.xml文件


  
             
   /;${VIDEOCHAT_DIR}
  

 

 

 

提个录制的问题:

根据网上资料:main.far中都改成yes,true但是反而没有权限了。。求助各位大侠!!都倒腾好几天了。。

另外问个小问题:写其他录制例子的时候不会自动生成streams文件夹。。特此求助,请各位大侠指点一二!

 

代码贴出:

import flash.text.TextFormat;
import flash.display.*;
import flash.text.*;
import flash.net.*;
import flash.events.*;
import flash.errors.*;
import flash.system.*;
import fl.managers.StyleManager;
import fl.controls.List;
import fl.data.DataProvider;
import fl.controls.TextArea;

//安全域
Security.allowDomain("*");
Security.allowInsecureDomain("*");
//定义变量
var fmsPath:String;
var myNC:NetConnection;
var myNS:NetStream;
var myNS2:NetStream;;//分支视频流 专门用来录像 
var time:String = null;//定义时间寄存器
var userName:String;
var msg:String;
var peopleArray:Array;
var mySO:SharedObject;
var tmpName:String;
var now:Date;
var mySubNS:NetStream;
var myCam:Camera;
var myMic:Microphone;

//组件样式
var myTF:TextFormat=new TextFormat();
myTF.size = 12;
StyleManager.setStyle("textFormat",myTF);
userName = "guest" + int(Math.random() * 10000);
userName1.text = userName;
userName2.text = "所有人";
now=new Date();
peopleList.addEventListener(MouseEvent.CLICK,selectChatTo);
peopleList.addEventListener(MouseEvent.DOUBLE_CLICK,getVideo);

plays.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);

//链接
myNC=new NetConnection();
myNC.client = this;
myNC.objectEncoding = ObjectEncoding.AMF0;
myNC.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
myNC.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncError);
myNC.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityError);
myNC.connect("rtmp://192.168.1.4/videoChat",userName);

function netStatus(event:NetStatusEvent):void
{
 trace(event.info.code);
 switch (event.info.code)
 {
  case "NetConnection.Connect.Success" :
   chatContent.htmlText +=  "连接成功!";
   setMySO();
   sendBtn.addEventListener(MouseEvent.MOUSE_DOWN,sendMsgByMouse);
   stage.addEventListener(KeyboardEvent.KEY_DOWN,sendMsgByKey);
   record.addEventListener(MouseEvent.CLICK,onRecord);
            stops.addEventListener(MouseEvent.CLICK,onStop);
   recordPublish();
   publishStream();
   break;
  case "NetConnection.Connect.Failed" :
   chatContent.htmlText +=  "连接失败!";
   break;
  case "NetConnection.Connect.Rejected" :
   chatContent.htmlText +=  event.info.application.message;
   break;

 }
}
function securityError(event:SecurityErrorEvent):void
{
 chatContent.htmlText +=  "安全性错误!";
}

//创建一个远程对象
function setMySO():void
{
 mySO = SharedObject.getRemote("mySO",myNC.uri,false);
 mySO.addEventListener(SyncEvent.SYNC,mySoSync);
 mySO.connect(myNC);
}

//利用远程共享对象创建在线列表
function asyncError(event:AsyncErrorEvent):void
{
}
function mySoSync(e:SyncEvent):void
{
 peopleArray = new Array  ;
 for (var tmp in mySO.data)
 {
  peopleArray.push(tmp);
 }
 var tmpDP:DataProvider = new DataProvider  ;
 for (var i=0; i {
  tmpName = peopleArray[i];
  tmpDP.addItem({label:tmpName});

 }
 tmpDP.sortOn("label");
 tmpDP.addItemAt({label:"所有人"},0);
 peopleList.dataProvider = tmpDP;
}
function sendMsgByMouse(event:MouseEvent):void
{
 sendMsg();
}
function sendMsgByKey(event:KeyboardEvent):void
{
 if (event.keyCode == 13)
 {
  sendMsg();
 }
}

function sendMsg():void
{
 if (willSendMsg.length > 0)
 {
  if (userName2.text = userName1.text)
  {
   chatContent.htmlText +=  "您不能对自己发言" + "\n";
   chatContent.verticalScrollPosition = chatContent.maxVerticalScrollPosition;

  }
  else
  {
   var allPeople:Array = new Array  ;
   for (var i=0; i   {
    if (peopleList.getItemAt(i).label != "所有人" && peopleList.getItemAt(i).label != userName1.text)
    {
     allPeople.push(peopleList.getItemAt(i).label);
    }
   }
   //利用html标签格式化被发送的聊天内容,突出显示用户名和发送时间
   msg=""+userName1.text+""+"对"+""+userName2.text+
   "
"+"说"+"("+""+now.getHours()+":"+((now.getMinutes()<10)?"0"+now.getMinutes():
       now.getMinutes())+":"+((now.getSeconds()<10)?"0"+now.getSeconds():now.getSeconds())+"
"+")"+":"+"\n"
   +willSendMsg.text+"\n";

   if (userName2.text == null)
   {
    userName2.text = "所有人";
   }

   //呼叫服务器端函数,并传递参数
   myNC.call("msgFromClient",null,userName1.text,userName2.text,msg,allPeople);
   chatContent.htmlText +=  msg;
   chatContent.verticalScrollPosition = chatContent.maxVerticalScrollPosition;
   willSendMsg.text = "";
  }
 }
}
//客户端获取服务器信息
function msgFromSrvr(msg)
{
 trace(msg);
 chatContent.htmlText +=  msg;
 chatContent.verticalScrollPosition = chatContent.maxVerticalScrollPosition;

}
//选择聊天对象
function selectChatTo(event:MouseEvent):void
{
 userName2.text = peopleList.selectedItem.label;
}
//发布自己视频
function publishStream():void
{
 liveVideo.visible = true;
 myCam = Camera.getCamera();
 myMic = Microphone.getMicrophone();
 liveVideo.attachCamera(myCam);
 myNS = new NetStream(myNC);
 myNS.client = this;
 myNS.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
 myNS.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncError);
 myNS.attachCamera(myCam);
 myNS.attachAudio(myMic);
 myNS.publish(userName1.text,"live");
}
//发布录制的视频
function recordPublish():void
{
 myNS2 = new NetStream(myNC);
 myNS2.client = this;
 myNS2.addEventListener(NetStatusEvent.NET_STATUS,netStreamHandler);
 myNS2.attachCamera(myCam);
 myNS2.attachAudio(myMic);
 myNS2.publish(userName1.text, "live");
 
}

//NetStream事件处理器 
function netStreamHandler(e:NetStatusEvent):void
{
 var s:String = e.info.code;
 switch (s)
 {//停止录像时,再记录当前时间,并以此为标志位,发不到FMS 
  case "NetStream.Record.Stop" :
   myNS2 = new NetStream(myNC);
   myNS2.attachAudio(Microphone.getMicrophone());
   myNS2.attachCamera(Camera.getCamera());
   myNS2.publish(time,"live");
   break;
 }
}

 

//显示对方视频
function getVideo(event:MouseEvent):void
{
 if (userName2.text != userName1.text)
 {
  whoseVideo.text = userName2.text + "的视频";
  mySubNS = new NetStream(myNC);
  mySubNS.client = this;
  mySubNS.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncError);
  mySubNS.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityError);
  mySubNS.play(userName2.text);
 }
 else
 {
  mySubNS.close();
  liveVideo.clear();
  whoseVideo.text = "我的视频";
  liveVideo.attachCamera(myCam);

 }
}


//录制视频
function onRecord(event:MouseEvent):void
{
 myNS2.attachCamera(myCam);
 myNS2.attachAudio(myMic);
 myNS2.publish("videoC", "record");
}
function onStop(event:MouseEvent):void
{
 myNS2.close();
}

//播放
var fl_Loader:Loader;

function fl_ClickToLoadUnloadSWF(event:MouseEvent):void
{
  fl_Loader = new Loader();
  fl_Loader.load(new URLRequest("Legendexc.swf"));
  fl_Loader.addEventListener(Event.COMPLETE,onComplete);
  addChild(fl_Loader);
//加载的播放器的swf里处理视频播放的代码
}

function onComplete(e:Event):void{
 var loader:Loader=e.currentTarget as Loader;
 loader.content.width=800;
 
}

你可能感兴趣的:(FMS)