Hi everyone,
I am developing a voice chat application for which i need to record the voice in amr format for 2-5 sec and send it to the server. But the thing is i'm unable to the record the voice itself in N70 where as the code works fine in emulator Java(TM) ME Platform SDK 3.0. My code to record the voice -
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.control.*;
import javax.microedition.media.*;
import javax.microedition.io.*;
import java.io.*;
import java.util.*;
import javax.microedition.io.file.*;
class RecordForm extends MIDlet implements CommandListener
{
private Display display;
private Form form;
private Command record;
private Command play;
private Command exit;
private Player p;
private byte[] recordedSoundArray = null;
public RecordForm()
{
display = Display.getDisplay(this);
record = new Command("Record", Command.SCREEN, 1);
play = new Command("Play", Command.SCREEN, 2);
exit=new Command("exit",Command.SCREEN,3);
form = new Form("Recording Example");
form.addCommand(record);
form.addCommand(play);
form.addCommand(exit);
form.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command comm, Displayable disp)
{
if(comm==record)
{
Thread t = new Thread()
{
public void run()
{
try
{
form.append("Recording your voice ...\n\n");
p = Manager.createPlayer("capture://audio");//?encoding=amr");
RecordControl rc = (RecordControl)p.getControl("RecordControl");
ByteArrayOutputStream output = new ByteArrayOutputStream();
rc.setRecordStream(output);
rc.startRecord();
p.start();
form.append("Recording...\n");
form.removeCommand(play);
Thread.currentThread().sleep(5000); // record for 5 seconds
form.append("done!");
form.addCommand(play);
p.stop();
rc.stopRecord();
rc.commit();
recordedSoundArray = output.toByteArray();
p.close();
}
catch (IOException ioe)
{
form.append("Error 1:"+ioe.toString());
}
catch (MediaException me)
{
form.append("Error 2:"+me.toString());
}
catch (InterruptedException ie)
{
form.append("Error 3:"+ie.toString());
}
}
};t.start();
}
else if(comm == play)
{
Thread a = new Thread()
{
public void run()
{
try
{
form.deleteAll();
form.append("playing...\n");
form.append("recorded sound = " +String.valueOf(recordedSoundArray.length)+"\n\n");
ByteArrayInputStream recordedInputStream = new ByteArrayInputStream(recordedSoundArray);
Player p2 = Manager.createPlayer(recordedInputStream,"audio/x-wav");
p2.prefetch();
p2.start();
}
catch (IOException ioe)
{
form.append("Error 3:"+ioe.toString());
}
catch (MediaException me)
{
form.append("Error 4:"+me.toString());
}
}
};a.start();
}
else if (comm==exit)
{
try
{
destroyApp(false);
notifyDestroyed();
}
catch (Exception ioe)
{
form.append("Error 5:"+ioe.toString());
}
}
}
}
Please tell me the changes to be made in this code to make this work in N70 phones.
Thanks in advance.

Reply With Quote



