MediaRecorder - record calls application

早过忘川 提交于 2019-12-18 09:44:21

问题


im trying to develope application that recording calls.

when im recording the output sound sounds very wired - electronic sounds instead the other person voice.

here is my code:

public class MainActivity extends Activity implements OnClickListener {
private Boolean Recording;
private Button btn_REC;
private MediaRecorder mrec;
private File audiofile = null;
private static final String TAG = "SoundRecordingDemo";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
    Recording = false;
    mrec = new MediaRecorder();
    btn_REC = (Button) findViewById(R.id.btn_record);
    btn_REC.setOnClickListener(this);
}

@Override
public void onClick(View v)
{
    if (!Recording)
    {
        try
        {
            startRecording();
            Recording = true;
        }
        catch (IOException e1)
        {
            e1.printStackTrace();
        }

        btn_REC.setText("RECORDING");
    }


    else
    {       
        stopRecording();
        btn_REC.setText("RECORD");
    }


}

protected void startRecording() throws IOException {
    mrec.setAudioSource(MediaRecorder.AudioSource.VOICE_DOWNLINK);
    mrec.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mrec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    if (audiofile == null) {
        File sampleDir = Environment.getExternalStorageDirectory();
        try {
            audiofile = File.createTempFile("ibm", ".3gp", sampleDir);
        } catch (IOException e) {
            Log.e(TAG, "sdcard access error");
            return;
        }
    }
    mrec.setOutputFile(audiofile.getAbsolutePath());
    mrec.prepare();
    mrec.start();
}

protected void stopRecording() {
    mrec.stop();
    mrec.release();
    processaudiofile();
}

protected void processaudiofile() {
    ContentValues values = new ContentValues(3);
    long current = System.currentTimeMillis();
    values.put(MediaStore.Audio.Media.TITLE, "audio" + audiofile.getName());
    values.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current / 1000));
    values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/3gpp");
    values.put(MediaStore.Audio.Media.DATA, audiofile.getAbsolutePath());
    ContentResolver contentResolver = getContentResolver();

    Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    Uri newUri = contentResolver.insert(base, values);

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, newUri));
}

}

when im trying to change the AudioSource to uplink or voice call its still the same. when i define this to MIC all works just fine but when i make a call still this strange sound begin...

any thoughts?

thanks!


回答1:


Use mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);

But as,Call Recording is not legal so many device not support the (MediaRecorder.AudioSource.VOICE_CALL/MediaRecorder.AudioSource.VOICE_DOWNLINK), Will work on some Device.

I have tested it on LG and working fine but not working with Nexus device.

So Instead These use MediaRecorder.AudioSource.MIC which is allowed by all devices.




回答2:


Again call record functionality, or rather

 mrec.setAudioSource(MediaRecorder.AudioSource.VOICE_DOWNLINK);

Is highly a device dependent stuff.

Some device does not allow Uplink, some block Downlink and some don't allow voice call. And yet there are devices that allow All kinds of Audio source.

For example: I use a Moto device which allows Uplink and Downlink. But not both at same time i.e voice call. So either I can record my voice, or senders voice.

You should try on different handset to verify this behaviour



来源:https://stackoverflow.com/questions/15178996/mediarecorder-record-calls-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!