语音通话录音Android中使用MediaRecorder [英] Voice Call recording in android using MediaRecorder

查看:400
本文介绍了语音通话录音Android中使用MediaRecorder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在录制通话内容时我做了一个服务,称为广播接收器来获得通话状态的问题。在TelephonyManager.EXTRA_STATE_OFFHOOK当收到呼叫我使用下面的code,记录通话

  recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.DEFAULT);
recorder.setOutputFile(audiofile.getAbsolutePath());
尝试 {
     。录音机prepare();
     recorder.start();
}
赶上(IllegalStateException异常E){
e.printStackTrace();
}赶上(IOException异常E){
e.printStackTrace();
}赶上(例外前)
{
ex.printStackTrace();
}
 

这code工作正常,并创建音频文件,但是当我听音频文件我只能听我的声音传出,来电者的声音不被记录

当我使用

  recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
 

而不是

  recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 

在上面code,它抛出异常的重codeR上再coder.start()失败;

这么好心帮我,我怎么可以记录来电者的声音。

解决方案

我也一年前有同样的疑问,<一个href="http://stackoverflow.com/questions/14728615/audiosource-voice-call-not-working-in-android-4-0-but-working-in-android-2-3">AudioSource.VOICE_CALL不工作在Android 4.0的,但是在Android 2.3的工作

recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL); 适用于有限的设备,它只会在其语音通话,不支持这样捕获异常,并从头再来从MIC录音,将让你更安全侧非支持的设备该设备给予例外。

i have a problem in recording a call i have made a service and called a broadcast receiver to get the call state. In TelephonyManager.EXTRA_STATE_OFFHOOK when the call is received i am using following code to record call

recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);                               recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setOutputFile(audiofile.getAbsolutePath());
try {
     recorder.prepare();
     recorder.start();
} 
catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) { 
e.printStackTrace();
} catch (Exception ex)
{
ex.printStackTrace();
}

this code is working fine and creates the audio file but when i listen the audio file i can only listen my outgoing voice , caller voice is not recorded

when i use

recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);

instead of

recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

in above code it throws exception of recoder fails on recoder.start();

so kindly help me how can i record caller voice.

解决方案

I also had the same doubt a year ago AudioSource.VOICE_CALL not working in android 4.0 but working in android 2.3

recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL); works on limited devices ,it will give exception only on that device in which voice call is not supported so catch the exception and start the recording from mic all over again that will keep you on safer side in non supported device.

这篇关于语音通话录音Android中使用MediaRecorder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆