【发布时间】:2017-11-13 22:12:29
【问题描述】:
问题是通话录音在 android 版本 6.0.1 之前工作正常,但在该 android 版本以上不能正常工作。
问题:-通话持续 1 分钟,但录音在 2 到 3 秒后停止。
此处编辑联系人文本:
edt_attempt_contact.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_RIGHT = 2;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (event.getX() >= (edt_attempt_contact.getRight() - edt_attempt_contact.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
if (!edt_attempt_contact.getText().toString().isEmpty()) {
Intent i = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + edt_attempt_contact.getText().toString()));
try {
startActivity(i);
}catch (SecurityException s){
s.printStackTrace();
}
try {
audioRecord();
} catch (IOException e) {
e.printStackTrace();
}
} else {
Toast.makeText(MainActivity.this, "Attempt Contact Number is required to call", Toast.LENGTH_SHORT).show();
}
return true;
}
}
return false;
}
});
}
这是通话录音的主要代码。
private void audioRecord() throws IOException {
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(root + "/"
.concat("_")
.concat(generateUniqueFileName())
.concat(".amr"));
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
recorder.start();
}
我已经获得了所有需要的 android 录制权限,但它在 android 6.0.1 以上版本中无法正常工作。提前感谢您的解决方案...
【问题讨论】:
-
请添加比“无法正常工作”更详细的问题描述。
-
通话持续 1 分钟,但录音会在几秒后立即停止,即以上版本为 3 秒...
-
对于 6.0.1 以上的版本是否需要在此代码中添加? @迈克尔
-
startActivity(i);如果失败,则会发生异常,并在尝试audioRecord();时失败 -
解决方案是什么@t0mm13b?
标签: android audio-recording mediarecorder android-mediarecorder voice-recording