录音通话永不结束
问题描述:
在这段时间里,我得到了一个不同的问题,我有一个应用程序来录制呼叫,但是recorder.start()永远不会结束。 这里是用于记录的代码:录音通话永不结束
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
recorder.setMaxDuration(1000);
recorder.prepare();
recorder.start();
这部分代码执行时按下一个按钮来调用一个号码。但是,当我按在AVD结束呼叫按钮,该代码永远不会运行:
phoneListener = new PhoneStateListener()
{
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
switch (state)
{
case TelephonyManager.CALL_STATE_IDLE:
currentPhoneState = "CALL_STATE_IDLE";
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
currentPhoneState = "CALL_STATE_OFFHOOK";
break;
case TelephonyManager.CALL_STATE_RINGING:
currentPhoneState = "CALL_STATE_RINGING";
break;
}
_fileTrace.onTrace("INFO", "CallState: ", currentPhoneState, null);
if (currentPhoneState == "CALL_STATE_OFFHOOK")
{
llamada = true;
_fileTrace.onTrace("INFO", "Recording Start", currentPhoneState, null);
try {
recorder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
if (llamada && currentPhoneState == "CALL_STATE_IDLE") {
_fileTrace.onTrace("INFO", "CallState: ", currentPhoneState, null);
recorder.stop();
}
}
};
_CurrTelephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
供参考:第一部分的代码是一个辅助类和第2个是在活动。
我希望有人能帮助我。 谢谢大家!
答
我用下面的代码和它的工作:
public void onReceive(Context context, Intent intent) {
// Toast.makeText(context, "calling now", Toast.LENGTH_LONG).show();
if (!intent.getAction().equals("android.intent.action.PHONE_STATE"))
return;
else {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
log.d(TAG, "RINGING NOW")
return;
} else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
StartRecording();
Log.d(TAG, "CALL ANSWERED NOW");
return;
} else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
Log.d(TAG, "ALL DONE IN ELSE IF...... !!");
StopRecording();
} else {
Log.d(TAG, "ALL DONE IN ELSE ...... !!");
}
}
}
一些Android开发人员帮助我吗? – AuTi 2012-02-13 13:27:30
最后的机会,这个职位的家伙! – AuTi 2012-02-15 13:40:19