tags:

views:

544

answers:

0

i am trying to create a simple audio chat app.. i got some help from the following link. http://sunil-gupta.blogspot.com/2008/06/two-way-av-chat-application-with-fms3.html. in the above link the author gave a simple 2 way chat app. in the above link they are using two separate streams for user1 and user2. i want to extend it to a group chat. but i want to create one stream which will be used by all the users participating in the groupchat. is it possible to have a single stream which captures voice of all the users and plays it for others in the group. i have changed the code as follows. Now the below code capturing audio but the other person can not hear the audio… what is the problem with this.

i am using red5 and actionscript3.0, flashcs3, windowsxp

import flash.media.Camera;
import flash.media.Microphone;
import flash.media.Video;
import flash.events.NetStatusEvent;
import flash.display.Sprite;
import flash.net.NetConnection;
import flash.net.NetStream;

var netConnection:NetConnection;
var rtmpStr:String;
var nsSubscribe:NetStream;
var nsPublish:NetStream;
var microphone:Microphone;
var counter:Number = 1;
//localhost can be replaced with your LAN IP or remote server IP points to FMS server.
rtmpStr="rtmp://SYSTEMIP/simplerecorder/";

attachMicrophone();

netConnection=new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS,checkForConnection);
netConnection.connect(rtmpStr);

function checkForConnection(event:NetStatusEvent):void {

    event.info.code == "NetConnection.Connect.Success";
    if (event.info.code) {
     nsPublish=new NetStream(netConnection);
     nsPublish.attachAudio(microphone);
     //a common stream in to which captures voice of all the users in the group
     nsPublish.publish("commonstream","live");
     nsSubscribe=new NetStream(netConnection);
     nsSubscribe..addEventListener(NetStatusEvent.NET_STATUS, NetStreamHandler);
     nsSubscribe.play("commonstream");
    }
}

function attachMicrophone() {
    microphone=Microphone.getMicrophone();
    microphone.gain=80;
    microphone.rate=12;
    microphone.setSilenceLevel(15,2000);
    microphone.addEventListener(ActivityEvent.ACTIVITY, activityHandler);
    microphone.addEventListener(StatusEvent.STATUS, statusHandler);

}


function activityHandler(event:ActivityEvent):void {
    trace("mic activity occured: " + event);
    statusMsg.text = "mic activity occured: "+(counter++)+"...." + event;
}

function statusHandler(event:StatusEvent):void {
    trace("statusHandler: " + event);
    statusMsg.text = "statusHandler: " +(counter++)+"...." + event; 
    statusMsg.text = "";
}


function btnStartListener(evt:MouseEvent):void {
    if (netConnection.connected == true) {
     statusMsg.text = "connection to server established...";
    } else {
     statusMsg.text = "connection to server failed.. Try again";
    }
}

function NetStreamHandler(event:NetStatusEvent):void {
    trace(event.info.code);
    switch (event.info.code) {
     case "NetStream.Play.StreamNotFound" :
      statusMsg.text = "Sorry. the stream u r trying to play is not found";
      break;
     case "NetStream.Play.Start" :
      statusMsg.text = "Playback of audio is started";
      break;
     case "NetStream.Play.Stop" :
      statusMsg.text = "play back of audio is over";
      break;
     case "NetStream.Unpublish.Success" :
      break;
    }
}


btnStart.addEventListener(MouseEvent.CLICK, btnStartListener);

if i am wrong can any one give some direction towards this thanks for any help