Skip to content
This repository was archived by the owner on Aug 21, 2020. It is now read-only.
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
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand All @@ -37,6 +37,12 @@ On *Android* you need to add a permission to `AndroidManifest.xml`:
```
<uses-permission android:name="android.permission.RECORD_AUDIO" />
```
### No Linking required react-native > 0.60.


### Auto Linking
react-native link react-native-audio


### Manual Installation

Expand Down
22 changes: 20 additions & 2 deletions android/src/main/java/com/rnim/rn/audio/AudioRecorderManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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(){
Expand All @@ -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;
}
}
}
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var AudioRecorder = {
MeasurementMode: false,
AudioEncodingBitRate: 32000,
IncludeBase64: false,
ProgressUpdateInterval: 1000,
AudioSource: 0
};

Expand Down
8 changes: 7 additions & 1 deletion ios/AudioRecorderManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],
"repository": {
"type": "git",
"url": "[email protected]:jsierles/react-native-audio.git"
"url": "[email protected]:shivam4ukhandelwal/react-native-audio.git"
},
"nativePackage": true
}