2012-06-08 69 views
1

我是Flash開發中的新手。我試圖創建一個Flash(我已經完成了該操作,並且可以將流保存到紅5服務器),我可以選擇將我自己的麥克風流發佈到red5服務器,並且我也可以選擇收聽已發佈的流。我將在兩臺不同的機器上使用同樣的閃光燈。我將通過爲這兩個機器發佈不同的麥克風然後我會嘗試打開來自相反的機器的流,以便我可以從2臺機器聊天2路音頻。如何通過red5服務器在音頻中進行雙向交互

例如從機器1發佈的流是Stream1。來自機器2的 發佈的流是Stream2。

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

我現在面臨的問題是,我必須實現雙向通信。那是我不能夠從1 machine.When聽到流2我從發佈第二臺機器流話,難度我的第一個流被斷開連接並被第二個流覆蓋。 任何人都可以給我一個適當的建議,如何糾正這一點,以達到gud 2路連接或如何流2個音頻在一起。

回答

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> 
+0

嘿感謝您的答覆,我已經解決了這個問題昨天本身,反正謝謝很多幫助 –

+0

您是否使用Future2020的答案建議的類似代碼自己實現?如果你能回覆,這將是一個很大的幫助。謝謝。 – Matical

相關問題