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