Skip to content

Commit 9c6716e

Browse files
committed
bugfix: use correct AudioSource for Android Marshmallow and above
On Android Marshmallow (6) and above, no recordings were possible and no files would be created. Instead, we get an error message regarding audio capture. [This issue](#41), however, briefly describes the solution, which is basically this patch. Now the calls seems to be recorded correclty (tested on Android 6.0.1). Note that even though the source says just `MIC`, both voices in the call are captured.
1 parent b172b1a commit 9c6716e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/com/callrecorder/android/RecordService.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,11 @@ private void startRecording(Intent intent) {
198198
recorder = new MediaRecorder();
199199

200200
try {
201-
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
201+
int source = MediaRecorder.AudioSource.VOICE_CALL;
202+
// For Marshmallow and above, VOICE_CALL doesn't work but MIC does:
203+
// https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#M
204+
if(android.os.Build.VERSION.SDK_INT >= 23) source = MediaRecorder.AudioSource.MIC;
205+
recorder.setAudioSource(source);
202206
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
203207
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
204208
fileName = FileHelper.getFilename(phoneNumber);

0 commit comments

Comments
 (0)