MediaRecorder - 记录通话应用程序 [英] MediaRecorder - record calls application
问题描述
我正在尝试开发记录通话的应用程序.
im trying to develope application that recording calls.
当我录制输出声音时听起来很有线 - 电子声音而不是其他人的声音.
when im recording the output sound sounds very wired - electronic sounds instead the other person voice.
这是我的代码:
public class MainActivity extends Activity implements OnClickListener {
private Boolean Recording;
private Button btn_REC;
private MediaRecorder mrec;
private File audiofile = null;
private static final String TAG = "SoundRecordingDemo";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Recording = false;
mrec = new MediaRecorder();
btn_REC = (Button) findViewById(R.id.btn_record);
btn_REC.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
if (!Recording)
{
try
{
startRecording();
Recording = true;
}
catch (IOException e1)
{
e1.printStackTrace();
}
btn_REC.setText("RECORDING");
}
else
{
stopRecording();
btn_REC.setText("RECORD");
}
}
protected void startRecording() throws IOException {
mrec.setAudioSource(MediaRecorder.AudioSource.VOICE_DOWNLINK);
mrec.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mrec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
if (audiofile == null) {
File sampleDir = Environment.getExternalStorageDirectory();
try {
audiofile = File.createTempFile("ibm", ".3gp", sampleDir);
} catch (IOException e) {
Log.e(TAG, "sdcard access error");
return;
}
}
mrec.setOutputFile(audiofile.getAbsolutePath());
mrec.prepare();
mrec.start();
}
protected void stopRecording() {
mrec.stop();
mrec.release();
processaudiofile();
}
protected void processaudiofile() {
ContentValues values = new ContentValues(3);
long current = System.currentTimeMillis();
values.put(MediaStore.Audio.Media.TITLE, "audio" + audiofile.getName());
values.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current / 1000));
values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/3gpp");
values.put(MediaStore.Audio.Media.DATA, audiofile.getAbsolutePath());
ContentResolver contentResolver = getContentResolver();
Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Uri newUri = contentResolver.insert(base, values);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, newUri));
}
}
当我尝试将 AudioSource 更改为上行链路或语音呼叫时,它仍然相同.当我将其定义为 MIC 时一切正常,但是当我拨打电话时仍然出现这种奇怪的声音...
when im trying to change the AudioSource to uplink or voice call its still the same. when i define this to MIC all works just fine but when i make a call still this strange sound begin...
有什么想法吗?
谢谢!
推荐答案
Use mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
Use mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
但由于通话录音不合法,因此许多设备不支持 (MediaRecorder.AudioSource.VOICE_CALL/MediaRecorder.AudioSource.VOICE_DOWNLINK),将在某些设备上工作.
But as,Call Recording is not legal so many device not support the (MediaRecorder.AudioSource.VOICE_CALL/MediaRecorder.AudioSource.VOICE_DOWNLINK), Will work on some Device.
我已经在 LG 上测试过它并且工作正常,但不适用于 Nexus 设备.
I have tested it on LG and working fine but not working with Nexus device.
因此,它们使用所有设备都允许的 MediaRecorder.AudioSource.MIC.
So Instead These use MediaRecorder.AudioSource.MIC which is allowed by all devices.
这篇关于MediaRecorder - 记录通话应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!