I want to create a voice recorder application in Android 3.0. The script, when I click the record button, should start recording, and when I click the stop button, it should stop recording.
After recording the voice, I want to play the recorded sound when I press the play button. and he should stop playing when I click the stop playing button. I tried the code for voice recording. but it saves the file in 3gpp format. therefore, it cannot be played on ma. so I tried changing the outputformat to "AMR_NB". but it crashes when I press the stop button. can anyone provide the code, otherwise plz will help me make it work by editing my code. This is my helper class ...
public class AudioRecorder { final MediaRecorder recorder = new MediaRecorder(); final String path; public AudioRecorder(String path) { this.path = sanitizePath(path); } private String sanitizePath(String path) { if (!path.startsWith("/")) { path = "/" + path; } if (!path.contains(".")) { path += ".3gp"; } return Environment.getExternalStorageDirectory().getAbsolutePath() + path; } public void start() throws IOException { String state = android.os.Environment.getExternalStorageState(); if(!state.equals(android.os.Environment.MEDIA_MOUNTED)) { throw new IOException("SD Card is not mounted. It is " + state + "."); }
and this is my activity class
public class audiorecording extends Activity { private Button start; private Button stop; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); start=(Button)findViewById(R.id.start); stop=(Button)findViewById(R.id.stop); final AudioRecorder recorder = new AudioRecorder("/audiometer/temp"); start.setOnClickListener(new OnClickListener() { public void onClick(View v) { try { recorder.start(); } catch (IOException e) {
source share