I am working on records a phone calls. When i start a record a phone call then it's unfortunately stop. & it's gives error MediaRecorder start fail -2147483648. I refer this answer link. But i don't understand. Please tell me what is the problem in my code? Here is my Code.
我正在写电话记录。当我开始录制一个电话时,不幸的是,它停止了。它给出错误的MediaRecorder开始失败-2147483648。我引用这个答案链接。但是我不明白你的意思。请告诉我,我的代码有什么问题?这是我的代码。
public class IncomingCall extends BroadcastReceiver {
Context pcontext;
private static MediaRecorder recorder;
private boolean recordedStart = false;
@SuppressWarnings("unchecked")
public void onReceive(Context context, Intent intent) {
pcontext = context;
recorder = new MediaRecorder();
try {
TelephonyManager tmgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
MyPhoneStateListener PhoneListener = new MyPhoneStateListener();
tmgr.listen(PhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
} catch (Exception e) {
Log.e("Phone Receive Error", " " + e);
}
}
private class MyPhoneStateListener extends PhoneStateListener {
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
Log.e("MyPhoneListener",state+" incoming no:"+incomingNumber);
Log.e("CALL_STATE_RINGING", "CALL_STATE_RINGING");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setOutputFile(Environment.getExternalStorageDirectory()+"/MyRecorder.mp3");
Log.e("Path", ""+Environment.getExternalStorageDirectory()+"/MyRecorder.mp3");
try {
recorder.prepare();
recorder.start();
recordedStart = true;
Log.e("Start", "Recorder Start");
} catch (IllegalStateException | IOException e) {
// TODO Auto-generated catch block
Log.e("Error", ""+e);
}
break;
case TelephonyManager.CALL_STATE_IDLE:
Log.e("CALL_STATE_IDLE", "CALL_STATE_IDLE");
if (recordedStart == true) {
recorder.stop();
recorder.release();
recordedStart = false;
Log.e("Stop", "Recorder Stop");
}
break;
}
}
}
}
}
Logcat Error
Logcat错误
05-05 10:57:23.771: E/MediaRecorder(12812): start failed: -2147483648
05-05 10:57:23.771: D/AndroidRuntime(12812): Shutting down VM
05-05 10:57:23.771: W/dalvikvm(12812): threadid=1: thread exiting with uncaught exception (group=0x416bdd40)
05-05 10:57:23.774: E/AndroidRuntime(12812): FATAL EXCEPTION: main
05-05 10:57:23.774: E/AndroidRuntime(12812): Process: web.revolution.autocallanswer, PID: 12812
05-05 10:57:23.774: E/AndroidRuntime(12812): java.lang.RuntimeException: start failed.
05-05 10:57:23.774: E/AndroidRuntime(12812): at android.media.MediaRecorder.start(Native Method)
05-05 10:57:23.774: E/AndroidRuntime(12812): at web.revolution.autocallanswer.IncomingCall$MyPhoneStateListener.onCallStateChanged(IncomingCall.java:98)
05-05 10:57:23.774: E/AndroidRuntime(12812): at android.telephony.PhoneStateListener$2.handleMessage(PhoneStateListener.java:389)
05-05 10:57:23.774: E/AndroidRuntime(12812): at android.os.Handler.dispatchMessage(Handler.java:102)
05-05 10:57:23.774: E/AndroidRuntime(12812): at android.os.Looper.loop(Looper.java:136)
05-05 10:57:23.774: E/AndroidRuntime(12812): at android.app.ActivityThread.main(ActivityThread.java:5102)
05-05 10:57:23.774: E/AndroidRuntime(12812): at java.lang.reflect.Method.invokeNative(Native Method)
05-05 10:57:23.774: E/AndroidRuntime(12812): at java.lang.reflect.Method.invoke(Method.java:515)
05-05 10:57:23.774: E/AndroidRuntime(12812): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
05-05 10:57:23.774: E/AndroidRuntime(12812): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
05-05 10:57:23.774: E/AndroidRuntime(12812): at dalvik.system.NativeStart.main(Native Method)
05-05 10:57:25.586: I/Process(12812): Sending signal. PID: 12812 SIG: 9
05-05 10:57:27.052: E/CALL_STATE_IDLE(13255): CALL_STATE_IDLE
3 个解决方案
#1
11
this problem causing by this Audio source
这个问题是由这个音频源引起的。
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
not working on your device and android! change that to
不使用你的设备和android!改变,
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
or other sources.
或其他来源。
also you can remove FC by change recorderstart() to try/catch with IllegalStateException,Exception same as this
还可以通过更改recorderstart()来删除FC,以尝试/捕获与IllegalStateException相同的异常。
try {
recorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
Log.d("ERROR ","IllegalStateException");
} catch (Exception e) {
// TODO Auto-generated catch block
Log.d("ERROR ","IOException");
e.printStackTrace();
}
try {
recorder.start();
} catch (Exception e) {
}
i had this problem my self,this is working great for call recording but having problem with receiver voice quality is very low if you find solution of this tel me too.
我有这个问题,我的自我,这是很好的电话录音,但是如果你找到了这个电话的解决方案我也有问题,接收语音质量很低。
#2
1
I faced the same problem when I tried to record VOICE_CALL/VOICE_DOWNLINK/VOICE_UPLINK on my Nexus5. I don't want to talk long, this problem is indecisive on many smartphones under Android. But there are several devices that work's normally with this audio source. One of them is Samsung specifically Note3 (Android 4.3). I tried this on that device and everything been allright. As I heard that this problem will appear again when the update 4.4.2/3 reaches Note3, probably because of conflicts with U.S. law. But now you may use this feature on Note3 without any conditions.
当我尝试在我的Nexus5上记录VOICE_CALL/VOICE_DOWNLINK/VOICE_UPLINK时,我遇到了同样的问题。我不想长话短说,这个问题对Android下的许多智能手机来说都是不确定的。但是有一些设备通常使用这个音频源工作。其中一个是三星专门的Note3 (Android 4.3)。我在那个设备上试过了,一切都很好。当我听说这个问题会在更新4.4.2/3到达Note3时再次出现,可能是由于与美国法律的冲突。但是现在您可以在Note3上没有任何条件地使用这个特性。
If you use this audio source on other device you will have to prevent the crash of application with this code:
如果您在其他设备上使用此音频源,您将不得不使用以下代码防止应用程序崩溃:
try {
mRecorder.start();
} catch (Throwable t) {
t.printStackTrace();
Log.w(LOG_TAG, t);
}
Then you will not any problems with this issue...
那么你对这个问题不会有任何问题……
What other device that would work fine with this source, I don't know. I tested only on Note3. Interesting how it's work on Galaxy3/4/5.
我不知道还有什么其他的设备可以使用这个源。我只在Note3上做了测试。有趣的是它是如何在星系3/4/5上工作的。
#3
0
I know its late to answer, but for others who have the same problem, my solution is to set the audio source to MediaRecorder.AudioSource.VOICE_COMMUNICATION
, so the receiver's voice quality won't decrease.
我知道答案很晚,但对于其他有同样问题的人,我的解决方案是将音频源设置为MediaRecorder.AudioSource。VOICE_COMMUNICATION,所以接收机的声音质量不会降低。
#1
11
this problem causing by this Audio source
这个问题是由这个音频源引起的。
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
not working on your device and android! change that to
不使用你的设备和android!改变,
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
or other sources.
或其他来源。
also you can remove FC by change recorderstart() to try/catch with IllegalStateException,Exception same as this
还可以通过更改recorderstart()来删除FC,以尝试/捕获与IllegalStateException相同的异常。
try {
recorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
Log.d("ERROR ","IllegalStateException");
} catch (Exception e) {
// TODO Auto-generated catch block
Log.d("ERROR ","IOException");
e.printStackTrace();
}
try {
recorder.start();
} catch (Exception e) {
}
i had this problem my self,this is working great for call recording but having problem with receiver voice quality is very low if you find solution of this tel me too.
我有这个问题,我的自我,这是很好的电话录音,但是如果你找到了这个电话的解决方案我也有问题,接收语音质量很低。
#2
1
I faced the same problem when I tried to record VOICE_CALL/VOICE_DOWNLINK/VOICE_UPLINK on my Nexus5. I don't want to talk long, this problem is indecisive on many smartphones under Android. But there are several devices that work's normally with this audio source. One of them is Samsung specifically Note3 (Android 4.3). I tried this on that device and everything been allright. As I heard that this problem will appear again when the update 4.4.2/3 reaches Note3, probably because of conflicts with U.S. law. But now you may use this feature on Note3 without any conditions.
当我尝试在我的Nexus5上记录VOICE_CALL/VOICE_DOWNLINK/VOICE_UPLINK时,我遇到了同样的问题。我不想长话短说,这个问题对Android下的许多智能手机来说都是不确定的。但是有一些设备通常使用这个音频源工作。其中一个是三星专门的Note3 (Android 4.3)。我在那个设备上试过了,一切都很好。当我听说这个问题会在更新4.4.2/3到达Note3时再次出现,可能是由于与美国法律的冲突。但是现在您可以在Note3上没有任何条件地使用这个特性。
If you use this audio source on other device you will have to prevent the crash of application with this code:
如果您在其他设备上使用此音频源,您将不得不使用以下代码防止应用程序崩溃:
try {
mRecorder.start();
} catch (Throwable t) {
t.printStackTrace();
Log.w(LOG_TAG, t);
}
Then you will not any problems with this issue...
那么你对这个问题不会有任何问题……
What other device that would work fine with this source, I don't know. I tested only on Note3. Interesting how it's work on Galaxy3/4/5.
我不知道还有什么其他的设备可以使用这个源。我只在Note3上做了测试。有趣的是它是如何在星系3/4/5上工作的。
#3
0
I know its late to answer, but for others who have the same problem, my solution is to set the audio source to MediaRecorder.AudioSource.VOICE_COMMUNICATION
, so the receiver's voice quality won't decrease.
我知道答案很晚,但对于其他有同样问题的人,我的解决方案是将音频源设置为MediaRecorder.AudioSource。VOICE_COMMUNICATION,所以接收机的声音质量不会降低。