0

我正在创建一个通话录音应用程序,当我试图停止通话录音时,Java 中的调试控制台说:“MediaRecorder stop 在无效状态下调用:4”我搜索了很多,但我找不到任何东西这可以帮助我!我已经在使用RECORD_AUDIOWRITE_EXTERNAL_STORAGE权限!这是我的代码的一部分:

private class PhoneCallListener extends PhoneStateListener {
    private boolean isPhoneCalling = false;
    @SuppressWarnings("deprecation")
    @Override
    public void onCallStateChanged(int state, final String incomingNumber) {
        // TODO Auto-generated method stub
        super.onCallStateChanged(state, incomingNumber);
        String path = Environment.getExternalStorageDirectory()+"/callrec/";
        final MediaRecorder recorder = new MediaRecorder();
        recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        recorder.setOutputFile(path+"/TEST00000000011110.M4A");
        if (TelephonyManager.CALL_STATE_RINGING == state) {

        }
        if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
            isPhoneCalling = true;
            try {
                recorder.prepare();
                recorder.start();
            } catch (Exception e) {
            }
        }
        if (TelephonyManager.CALL_STATE_IDLE == state) {
            if (isPhoneCalling) {
                try {
                    recorder.stop();
                    recorder.reset();
                    recorder.release();
                } catch (Exception e) {
                    // TODO: handle exception
                }
                Intent i = getBaseContext().getPackageManager()
                        .getLaunchIntentForPackage(
                                getBaseContext().getPackageName());
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(i);
                isPhoneCalling = false;
            }
        }
    }
}
4

1 回答 1

-4

终于我找到了解决问题的方法!我在课堂上创建了一个:public void Recorder(),当我想录制音频呼叫时,我还创建了一个停止录制的函数!我希望这对你有用!而且这个 MediaRecorder API 在 android 2.3.3 到 4.3 上运行良好!

于 2013-11-13T12:23:47.890 回答