1

我是 Flash 开发的新手。我正在尝试创建一个 flash(我已经做到了,并且可以将流保存到 red 5 服务器),在其中我可以选择将我自己的麦克风流发布到 red5 服务器,而且,我有收听已发布的流的选项。我将在两台不同的机器上使用相同的闪光灯。我将通过为流提供不同的名称来发布两台机器的麦克风。然后我将尝试打开来自对面机器的流,所以我可以从 2 台机器上进行 2 路音频聊天。

例如,从机器 1 发布的流是 Stream1。从机器 2 发布的流是 Stream2。

The stream played from machine 1 was Stream2.
The stream played from machine 2 was Stream1.

我面临的问题是我很难实现双向通信。也就是说,我无法从第一台机器听到流 2。当我从第二台机器发布流时,我的第一个流被断开并且是被第二个流覆盖。谁能给我一个适当的建议,如何纠正这个问题以实现 gud 2 路连接,或者我如何将 2 个音频流在一起。

4

1 回答 1

0

                  好吧,要拥有一个使用 red5 和 flex 4.5 的音频聊天应用程序,您可以尝试下面的代码。当然,它应该根据您的目的进行调整:

语音聊天机 1          

    <mx:Script>
     <![CDATA[
         import mx.controls.Alert;
         
         private var netConnection:NetConnection;
         private var InsertStream:NetStream;
         private var getStream:NetStream;
         private var connectionUrl:String="rtmp://YOURSERVER/vchat";
         
         private function init():void
         {
             netConnection=new NetConnection();
             netConnection.connect(connectionUrl);
             netConnection.addEventListener(NetStatusEvent.NET_STATUS,connectHandler);
         }                                   
         
         private function connectHandler(e:NetStatusEvent):void
         {
          if(e.info.code=="NetConnection.Connect.Success")
          {                                            
            InsertStream=new NetStream(netConnection);
              InsertStream.attachAudio(Microphone.getMicrophone());
              InsertStream.publish("stream1","live");
              getStream=new NetStream(netConnection);
              getStream.attachAudio(Microphone.getMicrophone());
              getStream.play("stream2"); // play the machine 2 stream
          }
          else
          {
              Alert.show("server Problem");
          }                                
  }
 ]]>
 </mx:Script>
 

机器 2

    <mx:Script>
     <![CDATA[
         import mx.controls.Alert;
         
         private var netConnection:NetConnection;
         private var InsertStream:NetStream;
         private var getStream:NetStream;
         private var connectionUrl:String="rtmp://YOURSERVER/vchat";
         
         private function init():void
         {
             netConnection=new NetConnection();
             netConnection.connect(connectionUrl);
             netConnection.addEventListener(NetStatusEvent.NET_STATUS,connectHandler);
         }                                   
         
         private function connectHandler(e:NetStatusEvent):void
         {
          if(e.info.code=="NetConnection.Connect.Success")
          {                                            
              InsertStream=new NetStream(netConnection);
              InsertStream.attachAudio(Microphone.getMicrophone());
              InsertStream.publish("stream2","live");
              getStream=new NetStream(netConnection);
              getStream.attachAudio(Microphone.getMicrophone());
              getStream.play("stream1"); // play stream from the other machine
          }
          else
          {
              Alert.show("server Problem");
          }                                
  }
 ]]>
 </mx:Script>
于 2012-06-09T21:23:25.333 回答