2010-12-03 22 views
5

我正在嘗試使用小錄音從服務中找到聲壓級,但Android不會讓我訪問硬件。我收到以下錯誤,在logcat中:無法訪問AudioRecorder

alt text

錯誤來自於下面的代碼:

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

什麼情況是,recordInstance永遠不會正確創建,所以當它到達結束調用recordInstance.startRecording(),recordInstance仍然爲null。 Android在定義時拒絕我的程序請求。有人知道那些errno的含義嗎?我無法在網上找到列表。

AudioRecord Docs

感謝

回答

19

檢查三件事情:

  1. 您的權限(你需要給權限RECORD_AUDIO)

  2. 你有沒有運行此一次,不叫recordInstance 。發佈()?如果是這樣,您可能已經綁定了音頻資源,並且在您重新啓動手機之前可能無法工作。無論如何,我已經發現了我的經歷。

3.緩衝區大小。有一個靜態方法AudioRecord.getMinBufferSize()

+3

它是recordInstance.release()。謝謝 – FuegoFingers 2010-12-23 08:06:13