Android mediarecorder停止调用无效状态:4

时间:2013-11-10 14:43:40

标签: java android mediarecorder android-mediarecorder

大家好我正在创建一个通话录音应用, 当我试图停止呼叫记录时,java中的调试控制台说: “MediaRecorder停止调用无效状态:4” 我谷歌很多但我找不到任何可以帮助我! 我已经使用了RECORD_AUDIO和WRITE_EXTRENAL_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;
                }

        }
    }
}

0 个答案:

没有答案