MediaRecorder - 记录通话应用程序 [英] MediaRecorder - record calls application

查看:240
本文介绍了MediaRecorder - 记录通话应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试应用下发展的通话记录

im trying to develope application that recording calls.

在IM记录输出声音听起来很有线 - 电子音效代替
其他人的声音。

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

这是我的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));
}

}

当我尝试改变AudioSource上行链路或语音调用它仍然是相同的。
当我定义这个为MIC所有工作得很好,但是当我拨打电话还​​是这个陌生的声音开始...

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...

什么想法?

谢谢!

推荐答案

使用mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);

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

但作为,通话录音是不合法的很多设备不支持(MediaRecorder.AudioSource.VOICE_CALL / MediaRecorder.AudioSource.VOICE_DOWNLINK),将一些设备的工作。

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.

我已经测试了LG和工作正常,但无法与Nexus设备的工作。

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

因此​​,而不是这些使用MediaRecorder.AudioSource.MIC这是由所有的设备允许的。

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

这篇关于MediaRecorder - 记录通话应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆