我很难在电话上录制语音。 问题是它开始记录的很好,但是
我退出电话时触发onOutgoingCallEnded, 我记录了记录器,但记录为空 并且我检查了音频文件,但是即使我拨打电话超过15秒,它也只能记录2〜3秒。
我有检测出局和出局的代码。 我实现了语音记录
代码如下。
@Override
protected void onOutgoingCallStarted(Context ctx, String number,
Date start) {
Log.e("dialog","status : onOutgoingCallStarted");
recorder = new MediaRecorder();
String out = new SimpleDateFormat("dd-MM-yyyy hh-mm-ss").format(new Date());
File sampleDir = new File(Environment.getExternalStorageDirectory(), "/TestRecordingDasa1");
if (!sampleDir.exists()) {
sampleDir.mkdirs();
}
String file_name = "Record";
try {
audiofile = File.createTempFile(file_name, ".mp4", sampleDir);
} catch (IOException e) {
e.printStackTrace();
}
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audiofile.getAbsolutePath());
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(ctx.getApplicationContext(),"record started",Toast.LENGTH_SHORT).show();
recordstarted = true;
recorder.start();
Log.e("dialog","record:"+recorder.toString());
}
@Override
protected void onOutgoingCallEnded(Context ctx, String number, Date start, Date end) {
Log.e("dialog","status : onOutgoingCallEnded"+recorder.toString());
Toast.makeText(ctx.getApplicationContext(),"record stop"+recordstarted,Toast.LENGTH_SHORT).show();
if(recorder!=null){
recorder.stop();
}
}
我认为通话开始和结束时所有声音都应记录在文件中。