public void run()
{
try{
startTime=System.currentTimeMillis()/1000;
// creating the player depending on which constructor has been used
// if the constructor that takes a file name has been used the progressive download
// functionality will be used.

if (event.compareTo(PlayerListener.END_OF_MEDIA)==0 ) {
stopTime=System.currentTimeMillis()/1000;
System.out.println("playTime="+(stopTime-startTime));
// When the media has been played we close the player
player.close();
}
}
}

try{
// creating the player from the file url enabling progressive download
player = Manager.createPlayer(locator);
// adding playerListenter
player.addPlayerListener(this);
// allocating the resources from the microphone
player.realize();
// Getting the ReocrdControll so we can record the output from the player
rc = (RecordControl)player.getControl("RecordControl");
}
catch(Exception er){tb.setString(er.toString());}

if(flags[0]) // If we are saving the recorde audio to file
{
try{
// setting the record location to the file
rc.setRecordLocation("file:///c:/other/audio.amr");
// start recording
rc.startRecord();
// start to play the sound from the microphone
player.start();
}catch(Exception t){tb.setString(t.toString());}
}
else // If we are saving to an OutputStream
{
outputStream = null;
outputStream = new ByteArrayOutputStream();

if(rc==null)
System.out.println("rc==null");
// setting the record location to the outputstream
rc.setRecordStream(outputStream);

try{
// start recording
rc.startRecord();
// start to play the sound from the microphone
player.start();