我在設備上錄製聲音時遇到了一些問題。如果從Android開發人員網站(Site Link)我使用,代碼如下:在它關閉這兩個停止和啓動記錄(理論上是)主要佈局聲音錄製的權限問題
public void onClickStart(View v) throws IllegalStateException, IOException{
startRecord();
}
public void onClickStop(View v) throws IllegalStateException, IOException{
stopRecord();
}
private void startRecord() throws IllegalStateException, IOException{
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC); //ok so I say audio source is the microphone, is it windows/linux microphone on the emulator?
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile("/sdcard/test.3gpp");
recorder.prepare();
recorder.start();
}
private void stopRecord(){
recorder.stop();
// recorder.release();
}
,2個按鈕。
但是從logcat中嘗試了這一點,我的設備上時,我得到了以下錯誤(真的不能與試圖在模擬器上被人打擾):
Error 1:
ERROR/MediaRecorder(14541): start called in an invalid state: 4
java.lang.IllegalStateException: Could not execute method of the activity
Caused by: java.lang.reflect.InvocationTargetException
Error 2:
Caused by: java.io.FileNotFoundException: /sdcard/test.3gpp (Permission denied)
而且我也有我的清單設置以下權限。 xml文件:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />