I took this code from same forum I am trying to capture and then play the audio on other Computer but it is not working can any one help me i tried different methods of format but there is no out put please help me or any one can give me any other code related to JMF of voice chat I shall be thank full
// Capture and Send Audio
import java.io.*;
import java.util.Vector;
import javax.media.protocol.*;
import javax.media.*;
import javax.media.rtp.*;
import java.net.*;
import javax.media.format.AudioFormat;
public class CaptureNSend {
CaptureDeviceInfo di;
Processor process;
DataSource DSource;
SendStream sStream;
SessionManager sesManager;
SessionAddress sessionAdd;
RTPManager rtpMgr;
Processor p=null;
String IP;
MediaLocator Locate;
public CaptureNSend(String ip) {
IP = ip;
//AudioFormat format = new AudioFormat("LINEAR", 8000, 8, 1);
//Vector deviceList = CaptureDeviceManager.getDeviceList(new AudioFormat(AudioFormat.MPEG_RTP, 44100, 16, 2));
//Vector deviceList = CaptureDeviceManager.getDeviceList(new AudioFormat(AudioFormat.GSM_RTP,44100,16,2));
//Vector deviceList = CaptureDeviceManager.getDeviceList(new Format(AudioFormat.MPEG_RTP,44100,16,2));
Vector deviceList = CaptureDeviceManager.getDeviceList(new AudioFormat("linear", 44100, 16, 2));
//List list = CaptureDeviceManager.getDeviceList(new AudioFormat("linear", 44100, 16, 2));
System.out.println(deviceList.size());
if (deviceList.size() > 0) {
di = (CaptureDeviceInfo)deviceList.get(1);
System.out.println(di.getName());
di = (CaptureDeviceInfo)deviceList.get(deviceList.size() - 1);
System.out.println(di.getName());
}
else
System.exit(-1);
MediaLocator locate = di.getLocator();
Locate = locate;
try{
p = Manager.createProcessor(Locate);
p.addControllerListener(new ProcessorEventHandler());
p.configure();
}catch(Exception e){
e.printStackTrace();
}
}
public void setOutputFormat(){
p.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW_RTP));
System.out.println("Audio Format Set");
// transmitMedia();
}
public void setupSession () {
DSource = p.getDataOutput();
rtpMgr = RTPManager.newInstance();
System.out.println("source checked");
int port = 5000;
try {
InetAddress local=InetAddress.getLocalHost();
System.out.println("inetaddress checked");
sessionAdd = new SessionAddress(local,port);
InetAddress remote =InetAddress.getByName(IP);
SessionAddress tarAdd = new SessionAddress(remote,6638);
System.out.println(port);
System.out.println("Session address checked");
rtpMgr.initialize(sessionAdd);
rtpMgr.addTarget(tarAdd);
System.out.println("session add peer checked");
sStream = rtpMgr.createSendStream(DSource,0);
System.out.println("sending media");
sStream.start();
p.start();
} catch (Exception e) {
e.printStackTrace();
}
}
private class ProcessorEventHandler extends ControllerAdapter{
public void configureComplete(ConfigureCompleteEvent configureCompleteEvent) {
setOutputFormat();
System.out.println(" Configured");
p.realize();
}
public void realizeComplete (RealizeCompleteEvent realizeCompleteEvent) {
setupSession();
}
public void endOfMedia ( EndOfMediaEvent mediaEndEvent) {
stopTransmission();
System.out.println("Transmission completed.");
}
}
public void stopTransmission() {
}
public static void main(String[] args) {
CaptureNSend sCapture = new CaptureNSend("192.168.1.51");
}
}
-------------------------------------------------------------------
// Receive and Playback Audio
import javax.media.*;
import java.util.*;
public class ReceiveMedia{
String ip = "10.10.50.171";
int port = 5000;
Player player;
public ReceiveMedia(){
String location = "
rtp://" + ip + ":" + port + "/" + "audio" + "/1";
System.out.println("Setting up MediaLocator");
MediaLocator media = new MediaLocator(location);
try{
player = Manager.createPlayer(media);
player.addControllerListener(new PlayerHandlerEvent());
player.realize();
System.out.println("Player Realized");
} catch(Exception e){
e.printStackTrace();
}
}
public class PlayerHandlerEvent extends ControllerAdapter{
public void realizeComplete(RealizeCompleteEvent realizeDoneEvent){
player.prefetch();
}
public void prefetchComplete(PrefetchCompleteEvent prefetchDoneEvent){
player.start();
System.out.println("Start Playback");
} //end prefetchComplete method
public void endOfMedia(EndOfMediaEvent mediaEndEvent) {
player.setMediaTime(new Time(0));
player.stop();
}
}
}