J2ME Audio Record

This example is used to record the audio sound and play the recorded sound.

J2ME Audio Record


This example is used to record the audio sound  and play the recorded sound. In this example we are trying to capture the audio sound and encoded into the pcm format, the source code is as follows:






Player p = Manager.createPlayer("capture://audio?encoding=pcm");

In the whole application we try to show recording and playing of the audio, To play the audio sound we are using the following source code:

Player p2 = Manager.createPlayer(recordedInputStream,"audio/basic");


The Application is as follows:



import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;

public class RecordMIDlet extends MIDlet{
  public void startApp(){
  Display.getDisplay(this).setCurrent(new RecordForm());
  public void pauseApp(){}
  public void destroyApp(boolean unconditional){}

class RecordForm extends Form implements CommandListener{
  private StringItem messageItem;
  private StringItem errorItem;
  private final Command recordCommand, playCommand;
  private Player p;
  private byte[] recordedSoundArray = null;
  public RecordForm(){
  super("Record Audio");  
  messageItem = new StringItem("Record", "Click record to start recording.");
  errorItem = new StringItem("", "");
  recordCommand = new Command("Record", Command.SCREEN, 1);
  playCommand = new Command("Play", Command.SCREEN, 2);
  StringBuffer inhalt = new StringBuffer();  
  public void commandAction(Command comm, Displayable disp){
  p = Manager.createPlayer("capture://audio?encoding=pcm");
  RecordControl rc = (RecordControl)p.getControl("RecordControl");
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  recordedSoundArray = output.toByteArray();  
  } catch (IOException ioe) {
  } catch (MediaException me) {
  } catch (InterruptedException ie) {
  } else if(comm == playCommand) {
  try {
  ByteArrayInputStream recordedInputStream = new ByteArrayInputStream(recordedSoundArray);
  Player p2 = Manager.createPlayer(recordedInputStream,"audio/basic");
  }  catch (IOException ioe) {
  } catch (MediaException me) {

Download Source Code

Share on Google+Share on Google+

J2ME Audio Record

Posted on: December 2, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: J2ME Audio Record   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
July 4, 2011
thank you

hello thank u . i use this code but this code dont run in sony ericsson .this run in nokia. plz help me i need run all cell phone. plz help me .it is very necessary. mail me thank a lot
January 12, 2012
Speech recognition in J2ME

while running this program, the emulator suspends in "Is it OK to Record? " how can i run this program, and how can i convert this speech to text in J2ME. waiting 4 rply.
February 21, 2012
audio recording

in Audio recording source code pls tell me why .jar file is not created pls tell me.
August 1, 2012
Call recording using j2me

how to record a call using this code? pls...
December 5, 2012
How to run this code?

Please any one tell me how to run this code? when I copy this code into drjava it shows me error on the packages and asked about "Player class" what should I do to make this code run successfully. Please tell me in detail