Flex在线视频聊天 求解

发布于 2021-11-17 20:30:46 字数 3015 浏览 866 评论 5

 因为是前几天才学Flex,我现在要做一个在线视频聊天的东西,就用FMS+Flex,在网上找了一些例子,情况是只能在自己电脑上看自己,我在别的电脑上连接我的电脑的话就不行,两台电脑不可以看见对方。不知道怎么解决。现在我把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://localhost/PublishStreams");
                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://localhost/PublishStreams");
                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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

等风来 2021-11-21 02:36:34

我们要用的是asp.net,red5好像是java的吧

尐偏执 2021-11-20 15:40:08

试试RED5

奈何桥上唱咆哮 2021-11-20 05:08:59

这个是我修改以后的,还是在自己电脑上上测试通过,

<?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.*;
			
			import mx.controls.Alert;
			
			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 var puN:String;
			private var reN:String;
			
			private function onPublishClick():void
			{
				pnc = new NetConnection();
				pnc.connect("rtmp://192.168.0.110/PublishStreams");
				pnc.addEventListener(NetStatusEvent.NET_STATUS,onPublishNetStatusHandler);
				
				cam = Camera.getCamera();
				mic = Microphone.getMicrophone();
				this.PublishVideo.attachCamera(cam);
				
				puN=this.publishName.text;
				//Alert.show(puN);
			}

			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(puN,"live");
					
					this.publishName.editable=false;
				}
			}
			
			private function onRecordClik():void
			{
				rnc = new NetConnection();
				
				reN=this.receiveName.text;
				
				rnc.connect("rtmp://192.168.0.110/PublishStreams");
				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(reN,"live");  //这里的publishName必须与发布流的流名一致
					
					this.receiveName.editable=false;
				}
			}
		]]>
	</mx:Script>
	<mx:Label x="35" y="348" width="304" id="lbPublish"/>
	<mx:Label x="391" y="348" width="296" id="lbRecord"/>
	<mx:TextInput x="184" y="316" id="publishName"/>
	<mx:TextInput x="566" y="317" width="140" id="receiveName"/>
</mx:Application>

用其他电脑连接还是不行

明媚如初 2021-11-20 02:29:07

你帮我看看,是不是,单独Flex就是不行啊??必须要和asp或者其他整合才可以

奢望 2021-11-19 21:35:38

假设A,B两个人,那么A发布的流名字应该为streamA, B发布streamB,然后A播放streamB, B播放streamA。

你这个代码看起来是A,B发布的名字都是publishName,并且连接服务器的地址还是localhost,这个错误太严重了

首先是需要把netconnection对象连接的时候,传你局域网的ip,比如192.168.1.140之类的,然后在发布的时候,两端使用不同的名字发布,再播放对方的流名字(测试的话,可以先用文本框输入流名字)。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文