2
audiofile = File.createTempFile(file_name, ""+audio_format, sampleDir);
String path=Environment.getExternalStorageDirectory().getAbsolutePath();

audioSource = MediaRecorder.AudioSource.MIC;

recorder=new MediaRecorder();
recorder.setAudioSource(audioSource);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
recorder.setOutputFile(audiofile.getAbsolutePath()); 

//recorder.prepare(); 
//recorder.start();
//Handle IOException

  recorder.prepare();

  recorder.start();
  Log.d("TAG", "recording started");

该代码在 android2.3 上完美运行,但在 4.0 上无法运行它在 recorder.start() 上给出错误,我对此完全空白任何与之相关的建议都将被接受,在此先感谢

4

1 回答 1

0

试试这个也许会有所帮助

private MediaRecorder mRecorder = null;
 private static final String LOG_TAG = "MediaAudioCapture";
 ImageButton button_audio_button = (ImageButton) findViewById(R.id.audio_button);
  button_audio_button.setOnClickListener(new OnClickListener() {
  public void onClick(View record_button) {
  ImageButton audio_button = (ImageButton) record_button;
  if (!started_note_recording) {
    if (!started_recording) {
      startRecording();
      audio_button.setImageResource(R.drawable.audio_red);
     } else {
     stopRecording();
     audio_button.setImageResource(R.drawable.audio);
     }
    }
  }
 });
private void startRecording() {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setOutputFile(output.getAbsolutePath());
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
ImageButton button_audio_button = (ImageButton)findViewById(R.id.audio_button);
button_audio_button.setImageResource(R.drawable.audio);
 }
}
});
 try {
  mRecorder.prepare();
 } catch (IOException e) {
 Log.e(LOG_TAG, "prepare() failed");
}
mRecorder.start();
stopWatch.start();
}
于 2013-05-24T11:39:37.000 回答