• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

AudioRecord crashing app

Greetings,

I am just getting started with Android and I'm trying to instantiate an instance of AudioRecord - unfortunately, the app crashes upon instantiation while running in the emulator. Is this a known problem? Or is there a common mistake that developers make with regard to AudioRecord?

Code:
private AudioRecord audioIn;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        if(audioIn == null)
        {
        	int bufferSize = AudioRecord.getMinBufferSize(44100, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT);
        	audioIn = new AudioRecord(MediaRecorder.AudioSource.MIC,
        							  44100,
        							  AudioFormat.CHANNEL_IN_MONO,
        							  AudioFormat.ENCODING_PCM_16BIT,
        							  bufferSize);
        	System.out.println("Initialized AudioRecord.");
        }
    }

Error:
The application Test Audio Input (process com.spawn) has stopped unexpectedly. Please try again.

Thanks.

Matt
 
Back
Top Bottom