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()上给出错误,我对此完全空白 任何与之相关的建议都会被接受,提前致谢
答案 0 :(得分: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();
}