0

After recording an outgoing phone call, I am trying to play the recorded file - to make sure the call recording worked as expected (I am doing it using 'MediaPlayer'), but there is no sound. So I tried to access the actual file on the phone (simply attached the phone to the computer and accessed it's files). When I played it the recording it was in the right length but again no sound.

What am I missing?

This is how I record the phone call:

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
// recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

File callAudioFile = null;
try {
    File downloadsDir = context.getApplicationContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
    callAudioFile = File.createTempFile("deTuCelRecord", ".amr", downloadsDir);
} catch (IOException e) {
    e.printStackTrace();
}
assert callAudioFile != null;
audioFilePath = callAudioFile.getAbsolutePath();

recorder.setOutputFile(audioFilePath);
try {
    recorder.setOnErrorListener(new MediaRecorder.OnErrorListener() {
        @Override
        public void onError(MediaRecorder mr, int what, int extra) {
            Log.e("MediaRecorder", "MediaRecorder error " + what + " " + extra);
        }
    });
    recorder.prepare();
} catch (IllegalStateException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

recorder.start();

This is the code which ends the call recording:

recorder.stop();
recorder.release();

This is how I play the audio file:

MediaPlayer mPlayer = new MediaPlayer();
try {
    mPlayer.setDataSource(audioFilePath);
    mPlayer.prepare();
    Toast.makeText(getApplicationContext(), "PLAYING AUDIO", Toast.LENGTH_LONG).show();
    mPlayer.start();
    Log.d("PLAY_AUDIO", "Started playing audio");
} catch (IOException e) {
    Log.e("PLAY_AUDIO", "Failed to play audio");
}
Nir Hayun
  • 11
  • 4

2 Answers2

0

Please check this Accessibilty Service in your testing phone.

If you are trying to record call on Android Q. Please refer this link

You can try recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL); It need Manifest.permission.CAPTURE_AUDIO_OUTPUT permission.

Please check AudioSource Source documentation for difference between VOICE_CALL and VOICE_COMMUNICATION

Akshay
  • 752
  • 1
  • 8
  • 25
  • I tried using recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL), but it's causing a failure: Error receiving broadcast Intent { act=android.intent.action.PHONE_STATE flg=0x1000010 (has extras) } in com.android.detucel.TService$CallBr@7e3380c This seems to be related to permissions and no matter what I did I couldn't get the right permissions. I did add the CAPTURE_AUDIO_OUTPUT permission. – Nir Hayun Aug 23 '20 at 17:49
0

The issue was the android version - from android 10 it didn't allow me to record the call but on android 9 it did.

Nir Hayun
  • 11
  • 4