我正在尝试从两个电话来源单独和同时录制。这是我正在使用的代码
telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
listener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
StopRecording(recorder1);
StopRecording(recorder2);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
StartRecording_DownLink();
StartRecording_UpLink();
break;
case TelephonyManager.CALL_STATE_RINGING:
break;
}
}
};
telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
public void StartRecording_UpLink(){
recorder1 = new MediaRecorder();
recorder1.setAudioSource(MediaRecorder.AudioSource.VOICE_UPLINK);
recorder1.setOutputFormat(output_formats[currentFormat]);
recorder1.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder1.setOutputFile(getFilename(AUDIO_RECORDER_FOLDER_UPLINK));
recorder1.setOnErrorListener(errorListener);
recorder1.setOnInfoListener(infoListener);
try{
recorder1.prepare();
recorder1.start();
}catch (IllegalStateException e){
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
public void StartRecording_DownLink(){
recorder2 = new MediaRecorder();
recorder2.setAudioSource(MediaRecorder.AudioSource.VOICE_DOWNLINK);
recorder2.setOutputFormat(output_formats[currentFormat]);
recorder2.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder2.setOutputFile(getFilename(AUDIO_RECORDER_FOLDER_DOWNLINK));
recorder2.setOnErrorListener(errorListener);
recorder2.setOnInfoListener(infoListener);
try{
recorder2.prepare();
recorder2.start();
}catch (IllegalStateException e){
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
再一次要清楚,我想在呼叫/呼叫时同时从上行链接和下行链接录制。该程序仅记录上行链接。调用下行链路录制方法时会弹出错误。请帮助。