利用fms服务器和flex来做在线视频聊天
程序员文章站
2022-05-24 19:29:52
在线视频聊天的实现是本文讲解的重点,首页是FMS服务器的搭建,一定要选live的,不要选vod的,具体的flex的代码如下,感兴趣的朋友可以参考下,希望对大家有所帮助... 13-09-22...
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>
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>
上一篇: JavaScript实现简单精致的图片左右无缝滚动效果
下一篇: Maya常用快捷键大全