diff --git a/README.md b/README.md index f4df63de..5a505241 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ from the network, please submit a PR to that project or try `react-native-video` Install the npm package and link it to your project: ``` -npm install react-native-audio --save -react-native link react-native-audio +npm install https://github.com/shivam4ukhandelwal/react-native-audio.git + ``` On *iOS* you need to add a usage description to `Info.plist`: @@ -37,6 +37,12 @@ On *Android* you need to add a permission to `AndroidManifest.xml`: ``` ``` +### No Linking required react-native > 0.60. + + +### Auto Linking +react-native link react-native-audio + ### Manual Installation 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 f6cecf65..1177ff34 100644 --- a/android/src/main/java/com/rnim/rn/audio/AudioRecorderManager.java +++ b/android/src/main/java/com/rnim/rn/audio/AudioRecorderManager.java @@ -27,7 +27,8 @@ import android.os.Environment; import android.media.MediaRecorder; import android.media.AudioManager; -import android.support.v4.app.ActivityCompat; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import android.support.v4.content.ContextCompat; import android.util.Base64; import android.util.Log; @@ -64,6 +65,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) { @@ -129,6 +131,8 @@ public void prepareRecordingAtPath(String recordingPath, ReadableMap recordingSe recorder.setAudioEncodingBitRate(recordingSettings.getInt("AudioEncodingBitRate")); recorder.setOutputFile(destFile.getPath()); includeBase64 = recordingSettings.getBoolean("IncludeBase64"); + 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()); @@ -315,10 +319,17 @@ 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(){ @@ -339,4 +350,11 @@ 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 44f1bff8..1e49fc4f 100644 --- a/index.js +++ b/index.js @@ -42,6 +42,7 @@ var AudioRecorder = { MeasurementMode: false, AudioEncodingBitRate: 32000, IncludeBase64: false, + ProgressUpdateInterval: 1000, AudioSource: 0 }; diff --git a/ios/AudioRecorderManager.m b/ios/AudioRecorderManager.m index c500cd37..4eeb3ca1 100644 --- a/ios/AudioRecorderManager.m +++ b/ios/AudioRecorderManager.m @@ -125,7 +125,8 @@ - (NSString *) applicationDocumentsDirectory return basePath; } -RCT_EXPORT_METHOD(prepareRecordingAtPath:(NSString *)path sampleRate:(float)sampleRate channels:(nonnull NSNumber *)channels quality:(NSString *)quality encoding:(NSString *)encoding meteringEnabled:(BOOL)meteringEnabled measurementMode:(BOOL)measurementMode includeBase64:(BOOL)includeBase64) +RCT_EXPORT_METHOD(prepareRecordingAtPath:(NSString *)path sampleRate:(float)sampleRate channels:(nonnull NSNumber *)channels quality:(NSString *)quality encoding:(NSString *)encoding meteringEnabled:(BOOL)meteringEnabled measurementMode:(BOOL)measurementMode includeBase64:(BOOL)includeBase64 progressUpdateInterval:(int)progressUpdateInterval) + { _prevProgressUpdateTime = nil; [self stopProgressTimer]; @@ -150,6 +151,11 @@ - (NSString *) applicationDocumentsDirectory _audioSampleRate = [NSNumber numberWithFloat:44100.0]; _meteringEnabled = NO; _includeBase64 = NO; + _progressUpdateInterval = 250; + + if (progressUpdateInterval != nil) { + _progressUpdateInterval = progressUpdateInterval; + } // Set audio quality from options if (quality != nil) { diff --git a/package.json b/package.json index bf63076a..75d2294c 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ ], "repository": { "type": "git", - "url": "git@github.com:jsierles/react-native-audio.git" + "url": "git@github.com:shivam4ukhandelwal/react-native-audio.git" }, "nativePackage": true }