Android Lollipop及更高版本的语音通话录音无效

时间:2016-01-13 08:47:01

标签: android voice-recording

我在Android棒棒糖和更高版本录制语音通话时遇到问题。通过这段代码,我能够录制我的声音,但无法记录其他人的声音。

    public void startRecording() {
    if (recording == false) {


        Log.e("here", "--------Recorder_Sarted------" + fname);
        SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy");
        int randomPIN = (int) (Math.random() * 9000) + 1000;
        recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        String file = Environment.getExternalStorageDirectory().toString();
        String filepath = file + "/Aeris/Recording";
        File dir = new File(filepath);
        dir.mkdirs();
        Log.e("here ", "----------------" + sdf.format(Calendar.getInstance().getTime()) + " " + fname + " " + type);
        filepath += "/" + type + "-" + fname + "-" + sdf.format(Calendar.getInstance().getTime()) + "-" + randomPIN + ".3gp";
        recorder.setOutputFile(filepath);

        try {
            recorder.prepare();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        recorder.start();
        recording = true;
    }
}

此代码在android lollipop版本下工作正常。 请帮我解决这个问题

1 个答案:

答案 0 :(得分:0)

将音频源VOICE_COMMUNICATION发送到MIC(麦克风)

recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
Moto g2(Android 6.0),lenovo(Android 5.0)中的

经过测试,工作正常。

相关问题