1

我遇到了这个问题,无法解决这个问题,我直接从扬声器录制电话,所以当我得到 TelephonyManager 时。CALL_STATE_OFFHOOK我立即开始录制音频VOICE_CALL。这部分没关系,开始录音,但如果通话结束并开始新的通话,我会得到一个java.lang.IllegalStateException

我认为这是因为第一个通话仍在录制中...我尝试过这样做:
mRecorder.stop();
mRecorder.release();
mRecorder.reset();
但是没有运气,他们都给了我一个illegalStateException,我只想知道如何停止第一个通话记录并在没有错误的情况下录制一个新通话.

这是我的录音和呼叫处理代码,

//At least one call exists that is dialing, active, or on hold, and no calls are ringing or waiting.
if (state == TelephonyManager.CALL_STATE_OFFHOOK){

    if (record_calls == 1){
        record_enviroment();
    }
}

//when Idle = No activity.
if (state == TelephonyManager.CALL_STATE_IDLE){
     //Check for audio recorded and if exists post audio to server
}

public void record_enviroment(){

path = context.getFilesDir().getAbsolutePath() + "/";

try {

//Random number for file name
Random r = new Random( System.currentTimeMillis() );
i = 10000 + r.nextInt(20000);

// Save file local to app
mFileName = path + i + "_call_" + id_asociado + ".3gp";
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

try {
     mRecorder.prepare();
} catch (IOException e) {
    Log.e("AUDIO_RECORDER", "prepare() failed");
}

mRecorder.start();

} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
4

0 回答 0