import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.media.*; import javax.microedition.media.control.*; public class main extends MIDlet implements CommandListener { private Form form; private Command exit,start,stop,play; ByteArrayOutputStream output; private Player p; private RecordControl rc; private byte[] recordedSoundArray; public void startApp() { try { p=Manager.createPlayer("capture://audio?encoding=pcm"); } catch(Exception e) {} exit = new Command("Back", Command.BACK, 2); start = new Command("start", Command.OK, 1); stop = new Command("stop", Command.OK, 2); play = new Command("Play", Command.BACK, 1); form.addCommand(exit); form.addCommand(play); form.addCommand(stop) form.addCommand(start); form.setCommandListener(this); Display.getDisplay(this).setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean unconditional) { notifyDestroyed(); } public void commandAction(Command c, Displayable d) { if (c == exit) { destroyApp(true); } if (c == start) { try { p.realize(); rc=(RecordControl)p.getControl("RecordControl"); output=new ByteArrayOutputStream(); rc.setRecordStream(output); rc.startRecord(); form.append("Record started"); } catch(Exception e) {} } if (c == stop) { try { rc.commit(); recordedSoundArray=ouptut.toByteArray(); p.close; form.append("Record stopped"); } catch(Exception e) {} } if (c == play) { try { ByteArrayInputStream baos = new ByteArrayInputStream(recordedSoundArray); Player p2=Manager.createPlayer(baos, "audio/basic"); p2.prefetch(); p2.start(); } catch(Exception e) {} } } }