1
我正在嘗試在我的應用程序中錄製whatsapp音頻調用。我的代碼工作很好的SIM卡調用或簡單的錄音,但是當開始呼籲WhatsApp或Facebook Messenger,並開始在社交網絡錄音調用我得到runtimeExceptin和MediaRecorder啓動失敗。Android:使用MediaRecorder錄製音頻在whatsapp音頻調用期間給出runtimeException
我使用這個簡單的代碼。
private void startRecording() {
mRecorder = new MediaRecorder();
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mFileName += "/Asimkhanmak.3gp";
mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
// mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
// mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
mRecorder.setOutputFile(mFileName);
try {
mRecorder.prepare();
} catch (IOException e) {
Toast.makeText(this, "Pre "+ e, Toast.LENGTH_SHORT).show();
}
try {
mRecorder.start();
} catch (RuntimeException e) {
Toast.makeText(this, "Start "+ e, Toast.LENGTH_SHORT).show();
}
}
我也嘗試了Mic作爲AudioSource,但它沒有奏效。