8

我已经编写了这段代码来记录通话。它在 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();
    }
}
4

2 回答 2

6

使用这个片段

_recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_DOWNLINK 
| MediaRecorder.AudioSource.VOICE_UPLINK );

代替

_recorder.setAudioSource(android.media.MediaRecorder.AudioSource.VOICE_CALL);
于 2011-07-27T06:13:37.437 回答
2

通话录音仅适用于部分 Android 手机。它可能适用于运行 2.1 的一部手机,但不适用于运行 2.2 的其他型号。尽管 API 将在所有架构上编译和运行,但某些设备已在硬件中禁用此功能。

请参阅如何在 Android 中录制语音和录制通话?更多细节。

于 2011-07-27T04:20:55.267 回答