I am trying to create a really simple audio recording app.
I followed the guide here: http://www.brighthub.com/mobile/google- ... 40735.aspx for the audio recording elements.
My app uses start and stop buttons to begin and end a recording. When I press Start, the app dies with the
"Sorry!: The application AudioRec has stopped unexpectedly. Please try again." error message. I am not sure what I could be doing wrong. My code is below, if anyone can find what I am doing wrong please let me know.
Using java Syntax Highlighting
- import java.io.IOException;
- import java.lang.Object;
- import android.app.Activity;
- import android.media.MediaRecorder;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class AudioRec extends Activity
- {
- public String PATH_NAME = "/sdcard/Music/Records";
- MediaRecorder MRX = new MediaRecorder();
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- final Button button = (Button) findViewById(R.id.Button01);
- button.setOnClickListener(new View.OnClickListener()
- {
- public void onClick(View v)
- {
- MRX.setAudioSource(MediaRecorder.AudioSource.MIC);
- MRX.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
- MRX.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
- MRX.setOutputFile(PATH_NAME);
- try {
- MRX.prepare();
- } catch (IllegalStateException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- MRX.start();
- }
- });
- final Button button2 = (Button) findViewById(R.id.Button02);
- button2.setOnClickListener(new View.OnClickListener()
- {
- public void onClick(View v)
- {
- MRX.stop();
- MRX.release();
- }
- });
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Thanks


