【问题标题】:How to have 2 way interaction in audio through red5 server如何通过 red5 服务器在音频中进行 2 路交互
【发布时间】:2012-06-10 05:23:25
【问题描述】:

我是 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 个音频流在一起。

【问题讨论】:

    标签: flash flex4 streaming audio-streaming red5


    【解决方案1】:

    好吧,要拥有一个使用 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>
    

    【讨论】:

    • 谢谢你的回复,我昨天自己解决了这个问题,无论如何非常感谢你的帮助
    • 您是否使用 Future2020 的回答所建议的类似代码自行实现?如果你能回复,那将是一个很大的帮助。谢谢。
    猜你喜欢
    • 2016-07-19
    • 1970-01-01
    • 2010-09-15
    • 1970-01-01
    • 2010-12-29
    • 1970-01-01
    • 2017-06-13
    • 2013-05-09
    • 1970-01-01
    相关资源
    最近更新 更多