利用fms服务器和flex来做在线视频文件谈天

更新时间:15-10-24 11:51 热度:854
 

1.fms服务器的建造,必须要选live的,不要选vod的

2.flex的代码如下所述!

复制代码

代码如下所述:

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” fontsize=”12″ height=”388″>
<mx:panel x=”10″ y=”10″ width=”340″ height=”282″ layout=”absolute” title=”视频文件宣布端”>
<mx:videodisplay x=”0″ y=”0″ width=”320″ height=”240″ id=”publishvideo”/>
</mx:panel>
<mx:panel x=”366″ y=”10″ width=”340″ height=”282″ layout=”absolute” title=”视频文件收缴端” id=”playpan”>
<mx:videodisplay x=”0″ y=”0″ width=”320″ height=”240″ id=”recordvideo” />
</mx:panel>
<mx:button x=”106″ y=”316″ label=”宣布视频文件” fontweight=”normal” click=”onpublishclick()”/>
<mx:button x=”488″ y=”317″ label=”收缴视频文件” fontweight=”normal” click=”onrecordclik()”/>
<mx:script>
<![cdata[
import flash.events.*;
private var pnc:netconnection;
private var rnc:netconnection;
private var pns:netstream; //宣布流
private var rns:netstream;
private var cam:camera;
private var mic:microphone;
private var video:video;
private function onpublishclick():void
{
pnc = new netconnection();
pnc.connect("rtmp://ip/live");
pnc.addeventlistener(netstatusevent.net_status,onpublishnetstatushandler);
cam = camera.getcamera();
mic = microphone.getmicrophone();
this.publishvideo.attachcamera(cam);
}
private function onpublishnetstatushandler(evt:netstatusevent):void
{
this.lbpublish.text=evt.info.code;
if(evt.info.code=="netconnection.connect.success")
{
pns = new netstream(pnc);
pns.attachaudio(mic);
pns.attachcamera(cam);
pns.client=this;
pns.publish("publishname","live");
}
}
private function onrecordclik():void
{
rnc = new netconnection();
rnc.connect("rtmp://ip/live");
rnc.addeventlistener(netstatusevent.net_status,onreordnetstatushandler);
}
private function onreordnetstatushandler(evt:netstatusevent):void
{
this.lbrecord.text=evt.info.code;
if(evt.info.code=="netconnection.connect.success")
{
rns = new netstream(rnc);
rns.client=this;
video = new video();
video.width=320;
video.height=240;
video.attachnetstream(rns);
this.recordvideo.addchild(video);
rns.play("publishname","live"); //这处的publishname务必与宣布流的流名完全一样
}
}
]]>
</mx:script>
<mx:label x=”35″ y=”348″ width=”304″ id=”lbpublish”/>
<mx:label x=”391″ y=”348″ width=”296″ id=”lbrecord”/>
</mx:application>