MediaRecorder - Errors as soon as I try record

All your problems with Audio, Video and Images.

MediaRecorder - Errors as soon as I try record

Postby CitizenSmif » Mon Mar 21, 2011 9:13 pm

Hi,

I'm having issues trying to even get a basic sound recorder to work. This code errors as soon as soon as its ran (I've tried having the audio begin recording onClick and that is where it crashes)

Code: Select all
package com.test.soundrecorder;

import java.io.IOException;

import android.app.Activity;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class soundrecord extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
       
        final MediaRecorder record = new MediaRecorder();
        record.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        record.setAudioSource(MediaRecorder.AudioSource.MIC);
        record.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        record.setOutputFile("/tmp/test");
       
        try {
         record.prepare();
      } catch (IllegalStateException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      record.start();

        final Button button = (Button) findViewById(R.id.recordStop);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
               record.stop();
            }
        });
    }
}


Can anyone see where I'm going wrong?

Eventually, I want this code to record sound once it reaches a certain volume level - will this even be possible?
CitizenSmif
Junior Developer
Junior Developer
 
Posts: 17
Joined: Thu Feb 17, 2011 12:45 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 38 guests