大家好,我正在创建一个通话录音应用程序,当我试图停止通话录音时,Java 中的调试控制台说:“MediaRecorder stop 在无效状态下调用:4”我用谷歌搜索了很多,但我什么也找不到可以帮我 !我已经在使用 RECORD_AUDIO 和 WRITE_EXTRENAL_STORAGE 权限!这是我的代码的一部分:
private class PhoneCallListener extends PhoneStateListener {
private boolean isPhoneCalling = false;
@SuppressWarnings("deprecation")
@Override
public void onCallStateChanged(int state, final String incomingNumber) {
// TODO Auto-generated method stub
super.onCallStateChanged(state, incomingNumber);
String path = Environment.getExternalStorageDirectory()+"/callrec/";
final MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path+"/TEST00000000011110.M4A");
if (TelephonyManager.CALL_STATE_RINGING == state) {
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
isPhoneCalling = true;
try {
recorder.prepare();
recorder.start();
} catch (Exception e) {
}
}
if (TelephonyManager.CALL_STATE_IDLE == state) {
if (isPhoneCalling) {
try {
recorder.stop();
recorder.reset();
recorder.release();
} catch (Exception e) {
// TODO: handle exception
}
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
isPhoneCalling = false;
}
}
}
}