问题描述
我创建一个通话录音的应用程序,当我试图阻止调用java中记录调试控制台说:MediaRecorder停止所谓的无效状态:4我GOOGLE了很多,但我可以'找不到任何可以帮助我!我已经使用 RECORD_AUDIO
和 WRITE_EXTERNAL_STORAGE
权限!这里是我的code的一部分:
私有类PhoneCallListener扩展PhoneStateListener {
私人布尔isPhoneCalling = FALSE;
@燮pressWarnings(德precation)
@覆盖
公共无效onCallStateChanged(INT状态,最后弦乐incomingNumber){
// TODO自动生成方法存根
super.onCallStateChanged(州,incomingNumber);
字符串路径= Environment.getExternalStorageDirectory()+/ callrec /;
最后MediaRecorder记录=新MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.AMR_NB);
recorder.setOutputFile(路径+/ TEST00000000011110.M4A);
如果(TelephonyManager.CALL_STATE_RINGING ==州){ }
如果(TelephonyManager.CALL_STATE_OFFHOOK ==州){
isPhoneCalling = TRUE;
尝试{
。录音机prepare();
recorder.start();
}赶上(例外五){
}
}
如果(TelephonyManager.CALL_STATE_IDLE ==州){
如果(isPhoneCalling){
尝试{
recorder.stop();
recorder.reset();
recorder.release();
}赶上(例外五){
// TODO:处理异常
}
意向I = getBaseContext()。getPackageManager()
.getLaunchIntentForPackage(
。getBaseContext()getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(ⅰ);
isPhoneCalling = FALSE;
}
}
}
}
终于让我找到一种方法来解决我的问题!
我创建了一个:
公共无效记录()
在我的课,当我想要录制的音频叫它
此外,我创建了一个功能停止录音!
我希望这对你的工作!
而且这个MediaRecorder API可以很好的在Android 2.3.3到4.3!
I'm creating a call recording app, when I'm trying to stop call recording the Debug Console in java says that: "MediaRecorder stop called in an invalid state : 4" I've Googled a lot but I can't find anything that can help me! I'm already using RECORD_AUDIO
and WRITE_EXTERNAL_STORAGE
permissions! Here is part of my code:
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;
}
}
}
}
finally i found a way to fix my problem !i created a :public void Recorder()in my class and when i want to record audio call italso i created a function for stop recording !i hope this work for you !and also this MediaRecorder API works good on android 2.3.3 to 4.3 !
这篇关于MediaRecorder:停止所谓处于无效状态:4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!