diff --git a/sdk/android/src/java/org/webrtc/audio/WebRtcAudioRecord.java b/sdk/android/src/java/org/webrtc/audio/WebRtcAudioRecord.java index 65bf0885bf..d17ab32c9d 100644 --- a/sdk/android/src/java/org/webrtc/audio/WebRtcAudioRecord.java +++ b/sdk/android/src/java/org/webrtc/audio/WebRtcAudioRecord.java @@ -10,7 +10,6 @@ package org.webrtc.audio; -import android.annotation.TargetApi; import android.content.Context; import android.media.AudioFormat; import android.media.AudioManager; @@ -252,22 +251,15 @@ class WebRtcAudioRecord { int bufferSizeInBytes = Math.max(BUFFER_SIZE_FACTOR * minBufferSize, byteBuffer.capacity()); Logging.d(TAG, "bufferSizeInBytes: " + bufferSizeInBytes); try { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - // Use the AudioRecord.Builder class on Android M (23) and above. - audioRecord = createAudioRecordOnMOrHigher( - audioSource, sampleRate, channelConfig, audioFormat, bufferSizeInBytes); - } else { - // Use the old AudioRecord constructor for API levels below 23. - audioRecord = createAudioRecordOnLowerThanM( - audioSource, sampleRate, channelConfig, audioFormat, bufferSizeInBytes); - } + audioRecord = + new AudioRecord(audioSource, sampleRate, channelConfig, audioFormat, bufferSizeInBytes); } catch (IllegalArgumentException e) { - reportWebRtcAudioRecordInitError("AudioRecord build error: " + e.getMessage()); + reportWebRtcAudioRecordInitError("AudioRecord ctor error: " + e.getMessage()); releaseAudioResources(); return -1; } if (audioRecord == null || audioRecord.getState() != AudioRecord.STATE_INITIALIZED) { - reportWebRtcAudioRecordInitError("Creation or initialization of audio recorder failed."); + reportWebRtcAudioRecordInitError("Failed to create a new AudioRecord instance"); releaseAudioResources(); return -1; } @@ -291,7 +283,7 @@ class WebRtcAudioRecord { } if (audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) { reportWebRtcAudioRecordStartError(AudioRecordStartErrorCode.AUDIO_RECORD_START_STATE_MISMATCH, - "AudioRecord.startRecording failed - incorrect state: " + "AudioRecord.startRecording failed - incorrect state :" + audioRecord.getRecordingState()); return false; } @@ -315,27 +307,6 @@ class WebRtcAudioRecord { return true; } - @TargetApi(Build.VERSION_CODES.M) - private static AudioRecord createAudioRecordOnMOrHigher( - int audioSource, int sampleRate, int channelConfig, int audioFormat, int bufferSizeInBytes) { - Logging.d(TAG, "createAudioRecordOnMOrHigher"); - return new AudioRecord.Builder() - .setAudioSource(audioSource) - .setAudioFormat(new AudioFormat.Builder() - .setEncoding(audioFormat) - .setSampleRate(sampleRate) - .setChannelMask(channelConfig) - .build()) - .setBufferSizeInBytes(bufferSizeInBytes) - .build(); - } - - private static AudioRecord createAudioRecordOnLowerThanM( - int audioSource, int sampleRate, int channelConfig, int audioFormat, int bufferSizeInBytes) { - Logging.d(TAG, "createAudioRecordOnLowerThanM"); - return new AudioRecord(audioSource, sampleRate, channelConfig, audioFormat, bufferSizeInBytes); - } - private void logMainParameters() { Logging.d(TAG, "AudioRecord: "