You shout creat new MediaRecorder one time, so that you shout creat
new MediaRecorder() inside
part of buttonRecorder.
And also, you shout use method audioRecorder.stop().
if you correct 2 issue above, you will fix this bug.
if(v==buttonRecording){
audioRecorder = new MediaRecorder();
textRecording.setText("Recording");
textStopRecording.setText("");
audioRecorder.setAudioSource
(MediaRecorder.AudioSource.MIC);
audioRecorder.setOutputFormat
(MediaRecorder.OutputFormat.THREE_GPP);
audioRecorder.setAudioEncoder
(MediaRecorder.AudioEncoder.AMR_NB);
audioRecorder.setOutputFile(Path_Name);
audioRecorder.prepare();
audioRecorder.start(); // Recording is now
started
}
if(v==buttonStopRecording){
textStopRecording.setText("Stop Recording");
textRecording.setText("");
audioRecorder.stop();
// audioRecorder.reset(); // You can reuse the
object by going
//back to setAudioSource() step
audioRecorder.release(); // Now the object cannot
be reused
this is OK!!!
On Jan 24, 2:49 pm, "[email protected]" <[email protected]> wrote:
> I'm a student and currently doing my senior capstone project. I have
> problem with my codes on audio recording. whenever i clicked the
> record button in the emulator, it shows me an error alert, "The
> application Audiorecording (process....) has stopped unexpectedly.
> Please try again." can anyone help me? thanks
>
> public class AudioRecording extends Activity {
> /** Called when the activity is first created. */
>
> private Button buttonRecording, buttonStopRecording;
> private EditText textRecording, textStopRecording;
> public String Path_Name = "/sdcard/test.3gpp";
>
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.main);
>
> textRecording = (EditText) findViewById(R.id.text1);
> textStopRecording = (EditText) findViewById(R.id.text2);
> buttonRecording = (Button) findViewById(R.id.buttonRecording);
> buttonStopRecording = (Button) findViewById
> (R.id.buttonStopRecording);
> buttonRecording.setOnClickListener(new clicker());
> buttonStopRecording.setOnClickListener(new clicker());
> }
>
> class clicker implements Button.OnClickListener {
> public void onClick(View v)
>
> {
> MediaRecorder audioRecorder = new MediaRecorder();
>
> if(v==buttonRecording){
>
> textRecording.setText("Recording");
> textStopRecording.setText("");
>
>
> audioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
> audioRecorder.setOutputFormat
> (MediaRecorder.OutputFormat.THREE_GPP);
> audioRecorder.setAudioEncoder
> (MediaRecorder.AudioEncoder.AMR_NB);
> audioRecorder.setOutputFile(Path_Name);
> audioRecorder.prepare();
> audioRecorder.start(); // Recording is now started
> }
>
> if(v==buttonStopRecording){
> textStopRecording.setText("Stop Recording");
> textRecording.setText("");
> audioRecorder.stop();
> //audioRecorder.reset(); // You can reuse the
> object by going
> back to setAudioSource() step
> //audioRecorder.release(); // Now the object cannot
> be reused
>
> //String tag, label;
> //TimingLogger timeRecord = new TimingLogger(tag,
> label);
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---