我正在创建一个通话记录应用程序,当我试图停止呼叫记录时,java中的调试控制台说:“MediaRecorder停止调用无效状态:4”我已经搜索了很多但我可以'找到任何可以帮助我的东西!我已经在使用RECORD_AUDIO
和WRITE_EXTERNAL_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;
}
}
}
}
答案 0 :(得分:-4)
最后我找到了解决问题的方法! 我创建了一个: public void Recorder() 在我的课堂上,当我想录制音频时,请致电它 我也创建了一个停止录音的功能! 我希望这对你有用! 而且这个MediaRecorder API在android 2.3.3到4.3上运行良好!