0

通话记录器可以在大多数设备上录音,但不能在三星盛大上工作。意味着在传入或传出时开始录制并记录来自所选来源(麦克风等)的声音,但其他设备将停止录制声音(可能是录音机在通话中未从该来源获取数据的原因(Android 的用户隐私问题))。

我为此尝试了 AudioRecord 和 MediaRecorder,但问题仍未解决。

    private MediaRecorder recorder = null;
    recorder.setAudioSource(1);
    recorder.setOutputFormat(1);
    recorder.setAudioEncoder(1);
    recorder.setOutputFile(path);
    recorder.prepare();
    recorder.start();

我也试过audiorecord,但它不适用于这个问题。

4

1 回答 1

0

我将发布一个问题代码。此代码在我的应用程序中运行良好

公共无效onStart(意图意图,int startId){

    mSampleFile = null;
    if (mSampleFile == null) {

        String newFolder = "/Recording";

        String extStorageDirectory = Environment
                .getExternalStorageDirectory().toString();

        File myNewFolder = new File(extStorageDirectory + newFolder);

        if (!myNewFolder.exists()) {

            myNewFolder.mkdir();

        }

        try {

            if (myNewFolder != null) {

                mSampleFile = File.createTempFile(SAMPLE_PREFIX,
                        SAMPLE_EXTENSION, myNewFolder);
            }
        } catch (IOException e) {

        }
    }

    if (mSampleFile != null) {
        SharedPreferences mysharedprefs8 = getSharedPreferences(mypref32,
                MODE_MULTI_PROCESS);
        String status = mysharedprefs8.getString("pass", "AMR_NB");

        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
        if (status.equalsIgnoreCase("AMR")) {
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
        } else if (status.equalsIgnoreCase("MPEG")) {
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        } else if (status.equalsIgnoreCase("3GPP")) {
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        } else {
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
        }
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

        try {

            mRecorder.setOutputFile(mSampleFile.getAbsolutePath());

        } catch (IllegalStateException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        }
        mRecorder.setMaxDuration(600000);
        try {

            mRecorder.prepare();

        } catch (IllegalStateException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        mRecorder.start();
        mRecorder.setOnInfoListener(new OnInfoListener() {

            @Override
            public void onInfo(MediaRecorder mr, int what, int extra) {
                // TODO Auto-generated method stub

                try {
                    mRecorder.stop();
                    mRecorder.reset();
                    mRecorder.release();

                } catch (Exception e) {

                }

            }
        });

    }
于 2013-06-07T05:13:24.447 回答