Android 2.2 中的通话录音

发布于 2024-11-26 09:59:18 字数 1290 浏览 1 评论 0原文

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

I have written this code for recording Calls. It works fine in Android 2.1. In Android 2.2, it creates an output file with 0 bytes.

How I can solve this?

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();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北陌 2024-12-03 09:59:18

使用此代码片段

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

代替

_recorder.setAudioSource(android.media.MediaRecorder.AudioSource.VOICE_CALL);

Use this snippet

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

instead of

_recorder.setAudioSource(android.media.MediaRecorder.AudioSource.VOICE_CALL);
茶花眉 2024-12-03 09:59:18

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

请参阅如何在 Android 中录制语音和通话录音? 了解更多详情。

Call recording only works on some Android phones. It might work on one phone running 2.1, but not on a different model running 2.2. Although the API will compile and run on all architectures, some devices have disabled this feature in the hardware.

See How can I record voice and record Call in Android? for more details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文