diff --git a/android/src/main/java/com/rnim/rn/audio/AudioRecorderManager.java b/android/src/main/java/com/rnim/rn/audio/AudioRecorderManager.java index e4a87538..83510211 100644 --- a/android/src/main/java/com/rnim/rn/audio/AudioRecorderManager.java +++ b/android/src/main/java/com/rnim/rn/audio/AudioRecorderManager.java @@ -59,6 +59,7 @@ class AudioRecorderManager extends ReactContextBaseJavaModule { private boolean isPauseResumeCapable = false; private Method pauseMethod = null; private Method resumeMethod = null; + private int progressUpdateInterval = 1000; public AudioRecorderManager(ReactApplicationContext reactContext) { @@ -120,6 +121,7 @@ public void prepareRecordingAtPath(String recordingPath, ReadableMap recordingSe recorder.setAudioChannels(recordingSettings.getInt("Channels")); recorder.setAudioEncodingBitRate(recordingSettings.getInt("AudioEncodingBitRate")); recorder.setOutputFile(recordingPath); + setProgressUpdateInterval(recordingSettings.getInt("ProgressUpdateInterval")); } catch(final Exception e) { logAndRejectPromise(promise, "COULDNT_CONFIGURE_MEDIA_RECORDER" , "Make sure you've added RECORD_AUDIO permission to your AndroidManifest.xml file "+e.getMessage()); @@ -283,10 +285,18 @@ public void run() { if (!isPaused) { WritableMap body = Arguments.createMap(); body.putDouble("currentTime", stopWatch.getTimeSeconds()); + + int amplitude = recorder.getMaxAmplitude(); + if (amplitude == 0) { + body.putInt("currentMetering", -160); + } else { + body.putInt("currentMetering", (int) (20 * Math.log(((double) amplitude) / 32767d))); + } + sendEvent("recordingProgress", body); } } - }, 0, 1000); + }, 0, progressUpdateInterval); } private void stopTimer(){ @@ -307,4 +317,13 @@ private void logAndRejectPromise(Promise promise, String errorCode, String error Log.e(TAG, errorMessage); promise.reject(errorCode, errorMessage); } + + + private void setProgressUpdateInterval(int progressUpdateInterval) { + if(progressUpdateInterval < 100) { + this.progressUpdateInterval = 100; + } else { + this.progressUpdateInterval = progressUpdateInterval; + } + } } diff --git a/index.js b/index.js index bdc8bda3..99757c7f 100644 --- a/index.js +++ b/index.js @@ -40,7 +40,8 @@ var AudioRecorder = { MeteringEnabled: false, MeasurementMode: false, AudioEncodingBitRate: 32000, - IncludeBase64: false + IncludeBase64: false, + ProgressUpdateInterval: 1000, }; var recordingOptions = {...defaultOptions, ...options};