2

i want to make call recorder in android. i have the following code in which when i use MediaRecorder.AudioSource.VOICE_DOWNLINK | MediaRecorder.AudioSource.VOICE_UPLINK is recording call but not understandable when played. if use the same code for AudioSouce.MIC
then recorded file is understandable. here is my code

package com.example.callrecoder;

import java.io.File;
import java.io.IOException;

import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Button record_call = (Button)this.findViewById(R.id.record);
        final Button stop_recorder = (Button)this.findViewById(R.id.stop);
        final MediaRecorder _recorder = new MediaRecorder();
        record_call.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                //MediaRecorder _recorder = new MediaRecorder();



                    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.setAudioSource(MediaRecorder.AudioSource.VOICE_DOWNLINK | MediaRecorder.AudioSource.VOICE_UPLINK );
                        _recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
                        _recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
                        //_recorder.setOutputFile(Environment.getExternalStorageDirectory().getAbsolutePath()
                        //        + "/test.wav");
                        _recorder.setOutputFile("/sdcard/sample.3GPP");
                        _recorder.prepare();
                        _recorder.start();

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }


        });
        stop_recorder.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                try
                {
                    _recorder.stop();
                    _recorder.reset();
                    _recorder.release();
                }
                catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }


                //_recorder = null;

            }
        });
    }

    public void onClick(DialogInterface dialog, int which) {
        // TODO Auto-generated method stub

    }




} 

i want to record calls with AudioSource.downlink and uplink. plz help me to solve this problem. i m testing it on Samsang Galaxay Gio phone.

4

1 回答 1

1

Insted VOICE_CALL 使用 VOICE_RECOGNITION,,,

callRecorder = new MediaRecorder();                                         
callRecorder.reset();                                                       
callRecorder.setAudioSamplingRate(8000);                                    
callRecorder.setAudioEncodingBitRate(12200);                                
callRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_RECOGNITION);   
callRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);         
callRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);            
于 2017-08-02T06:42:00.097 回答