开发者

Cannot access AudioRecorder

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:

Cannot access AudioRecorder

The error comes from the following code:

AudioRecord recordI开发者_StackOverflow社区nstance = 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


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()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜