Question

I am trying to take small recordings to find the Sound Pressure Level from a service but Android wont give me access to the hardware. I get the following errors in Logcat:

alt text

The error comes from the following code:

AudioRecord recordInstance = null;

    // We're important...
    android.os.Process
            .setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);

    short bufferSize = 4096;// 2048;


    recordInstance = new AudioRecord(MediaRecorder.AudioSource.MIC, this //line 167
            .getFrequency(), this.getChannelConfiguration(), this
            .getAudioEncoding(), bufferSize); //object not created

    tempBuffer = new short[bufferSize];
    recordInstance.startRecording();

What happens is that recordInstance is never properly created and so when it gets to the end and calls recordInstance.startRecording(), recordInstance is still null. Android rejects my programs request at the definition. Does anyone know what those errno's indicate? I couldn't find a list online.

AudioRecord Docs

Thanks

Was it helpful?

Solution

Check three things:

  1. Your permissions (you need to give permission for RECORD_AUDIO)

  2. Have you run this once and not called recordInstance.release()? If so you may have tied up audio resources and it will likely not work until you restart the phone. I have found that in my experience anyway.

3.The buffer size. There is a static method AudioRecord.getMinBufferSize()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top