OnClickListener startRecord = new OnClickListener() {
public void onClick(View v) {
String audiodir = new String(Environment.getExternalStorageDirectory() + File.separator + "Test" + File.separator);
while (stop_rec == false){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
Date now = new Date();
String fileName = formatter.format(now) + ".raw";
String audiopath = new String(audiodir + fileName);
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
recorder.setOutputFile(audiopath);
try {
recorder.prepare();
} catch (Exception e){
e.printStackTrace();
}
recorder.start(); // Recording is now started
new RecordActivity().execute(); //waiting
recorder.stop();
recorder.reset();
recorder.release();
}
stop_rec = false;
}
};
//@Override
OnClickListener stopRecord = new OnClickListener() {
public void onClick(View v) {
stop_rec = true; //for stop recording
}
};`
嗨,我的问题在 recorder.setAudioSource(MediaRecorder.AudioSource.MIC) 的行上,它会生成一些 RuntimeException。
更多细节我看不到,因为还有另一个错误:“类文件编辑器,找不到源:源附件不包含文件 InvocationTargetException.class 的源......”
有谁能够帮我?