利用fms服务器和flex来做在线视频聊天
平面设计 2021-07-03 14:34www.168986.cn平面设计培训
1.FMS服务器的搭建,一定要选live的,不要选vod的
2.flex的代码如下!
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://.adobe./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.Suess")
{
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.Suess")
{
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://.adobe./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.Suess")
{
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.Suess")
{
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>
上一篇:cad中将一张图片插入另一种图纸上的方法
下一篇:Maya制作逼真的青蛙脸部动画
平面设计师
- 平面设计图怎么画 小学生画平面图
- 平面设计内容怎么写 平面设计的求职意向怎么写
- 平面设计图手绘 平面设计图手绘家具
- 平面设计多久能出师 平面设计要多久
- 女生做ui设计师有多累 女生为什么学ui的人很惨
- 哪里有学平面设计的学校 想学平面设计去哪里学
- 初学平面设计用哪个软件 平面设计初学者必备的
- 0基础学平面设计要多久 0基础自学平面设计
- 平面设计手绘培训 平面设计师培训班学费多少钱
- ui工作好找工作吗 ui好不好找工作
- 女生学室内设计吃香吗
- ps平面设计自学教程 平面设计ps入门教程
- 平面设计基础知识大全 平面设计基本常识
- 平面设计基础教学视频 平面设计教学零基础入门
- 平面设计基础教学 平面设计基础教学平时作业
- ui设计主要是学什么 ui设计一般是学什么