Skip to content
This repository has been archived by the owner on Aug 21, 2020. It is now read-only.

Add metering and progress upload interval configuration in Android #276

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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(){
Expand All @@ -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;
}
}
}
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ var AudioRecorder = {
MeteringEnabled: false,
MeasurementMode: false,
AudioEncodingBitRate: 32000,
IncludeBase64: false
IncludeBase64: false,
ProgressUpdateInterval: 1000,
};

var recordingOptions = {...defaultOptions, ...options};
Expand Down