Sohail Yasin
Sohail Yasin

Reputation: 344

Call Recording issue in WebRTC

I have developed an android app for WebRTC video calling which is working fine. Now requirement is to record audio of call and store it on external storage. i have tried MedieRecorder which is recording the audio and storing it, but facing one problem here. when i start recording audio voice stops at reciever side. Media Recorder did not allow webrtc to use mic.

i have tried following code.

private boolean startMediaRecorder(){
    recorder = new MediaRecorder();
    try{
        recorder.reset();
        //recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);

        recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);

        recorder.setAudioSamplingRate(8000);
        recorder.setAudioEncodingBitRate(12200);
        //recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
        //recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
       // String fileName = audiofile.getAbsolutePath();

        String fileName = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" +
                        CreateRandomAudioFileName(5) + "AudioRecording.3gp";
        recorder.setOutputFile(fileName);

        MediaRecorder.OnErrorListener errorListener = new MediaRecorder.OnErrorListener() {
            public void onError(MediaRecorder arg0, int arg1, int arg2) {
                Log.e(TAG, "OnErrorListener " + arg1 + "," + arg2);
               // terminateAndEraseFile();
            }
        };
        recorder.setOnErrorListener(errorListener);

        MediaRecorder.OnInfoListener infoListener = new MediaRecorder.OnInfoListener() {
            public void onInfo(MediaRecorder arg0, int arg1, int arg2) {
                Log.e(TAG, "OnInfoListener " + arg1 + "," + arg2);
                //terminateAndEraseFile();
            }
        };
        recorder.setOnInfoListener(infoListener);


        recorder.prepare();
        // Sometimes prepare takes some time to complete
        Thread.sleep(2000);
        recorder.start();
        isRecordStarted = true;
        return true;
    }catch (Exception e){
        e.getMessage();
        return false;
    }
}

I have also tried `recorder.setAudioSource(MediaRecorder.AudioSource.MIC); // recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);

How can i record audio during WebRTC call ? Any help will be most appreciated. thanks

Upvotes: 1

Views: 1714

Answers (2)

Smart Apps
Smart Apps

Reputation: 113

You need add this file RecordedAudioToFileController. In addition, please remember to setSamplesReadyCallback in this file PeerConnectionClient.

Upvotes: 1

Onix
Onix

Reputation: 692

Look at the RecordedAudioToFileController class. It's able to record audio stream to file in PCM format.

If you want to get regular compressed audio file in the output, like 3gp, mp3 etc, you have to manually create audio container, encode and write encoded samples to it.

Upvotes: 2

Related Questions