MediaRecorder正在录制时出现IllegalStateException:如何修复

时间:2013-07-06 07:04:22

标签: android telephonymanager android-mediarecorder

我遇到了这个问题并且无法理解它,我直接从扬声器录制来电,所以当我收到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();
}
}

0 个答案:

没有答案