在Android 2.2中录制呼叫

Kar*_*att 8 android voice-recording

我已经写了这段代码来录制电话.它在Android 2.1中运行良好.在Android 2.2中,它创建一个0字节的输出文件.

我怎么能解决这个问题?

MediaRecorder _recorder = new MediaRecorder();


public void start() throws IOException {
    try {
        String state = android.os.Environment.getExternalStorageState();
        if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
            throw new IOException("SD Card is not mounted.  It is " + state
                    + ".");
        }

        // make sure the directory we plan to store the recording in exists
        File directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
                + "/sam.wav").getParentFile();
        if (!directory.exists() && !directory.mkdirs()) {
            throw new IOException("Path to file could not be created.");
        }


        _recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL );
        _recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
        _recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        setOutputFile(Environment.getExternalStorageDirectory().getAbsolutePath()
                + "/test.wav");
        _recorder.prepare();
        _recorder.start();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

Nik*_*unj 6

使用此代码段

_recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_DOWNLINK 
| MediaRecorder.AudioSource.VOICE_UPLINK );
Run Code Online (Sandbox Code Playgroud)

代替

_recorder.setAudioSource(android.media.MediaRecorder.AudioSource.VOICE_CALL);
Run Code Online (Sandbox Code Playgroud)

  • 至少根据文档,VOICE_UPLINK的常量值为2,VOICE_DOWNLINK的常量值为3,因此ORing返回3 ......也许它有效,但在我看来它只记录DOWNLINK ...... (2认同)