我搜索了一下,确认这个问题不是重复的,发现有些问题还没有答案,有些回答也没有帮到我。
这是我的代码:
private void startRecording()
{
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mFileName += "/recordedHeckPost_.3gp";
mRecorder.setOutputFile(mFileName);
try {
mRecorder.prepare();
//Thread.sleep(2000);
mRecorder.start();
}
catch (InterruptedException e)
{ // TODO Auto-generated catch block
e.printStackTrace();
}
catch(IllegalStateException e)
{
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void stopRecording()
{
mRecorder.stop();
mRecorder.release();
mRecorder = null;
}
在 Nexus 5 上运行此代码后,我收到以下启动失败-38异常的消息:05-31 18:17:39.404: E/MediaRecorder(2464): start failed: -38
05-31 18:17:39.404: W/System.err(2464): java.lang.IllegalStateException
05-31 18:17:39.404: W/System.err(2464): at android.media.MediaRecorder.start(Native Method)
谢谢。