Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
feat(play-sound): play sound on capture (android)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgfidelis committed Apr 6, 2018
1 parent b0bd0de commit 6924218
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public void setUseCamera2Api(RNCameraView view, boolean useCamera2Api) {
view.setUsingCamera2Api(useCamera2Api);
}

@ReactProp(name = "playSoundOnCapture")
public void setPlaySoundOnCapture(RNCameraView view, boolean playSoundOnCapture) {
view.setPlaySoundOnCapture(playSoundOnCapture);
}

@ReactProp(name = "faceDetectorEnabled")
public void setFaceDetecting(RNCameraView view, boolean faceDetectorEnabled) {
view.setShouldDetectFaces(faceDetectorEnabled);
Expand Down
10 changes: 10 additions & 0 deletions android/src/main/java/org/reactnative/camera/RNCameraView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.media.CamcorderProfile;
import android.media.MediaActionSound;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.util.SparseArray;
Expand Down Expand Up @@ -54,6 +55,7 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
private Map<Promise, File> mPictureTakenDirectories = new ConcurrentHashMap<>();
private Promise mVideoRecordedPromise;
private List<String> mBarCodeTypes = null;
private Boolean mPlaySoundOnCapture = false;

private boolean mIsPaused = false;
private boolean mIsNew = true;
Expand Down Expand Up @@ -201,10 +203,18 @@ public void setBarCodeTypes(List<String> barCodeTypes) {
initBarcodeReader();
}

public void setPlaySoundOnCapture(Boolean playSoundOnCapture) {
mPlaySoundOnCapture = playSoundOnCapture;
}

public void takePicture(ReadableMap options, final Promise promise, File cacheDirectory) {
mPictureTakenPromises.add(promise);
mPictureTakenOptions.put(promise, options);
mPictureTakenDirectories.put(promise, cacheDirectory);
if (mPlaySoundOnCapture) {
MediaActionSound sound = new MediaActionSound();
sound.play(MediaActionSound.SHUTTER_CLICK);
}
super.takePicture();
}

Expand Down
3 changes: 3 additions & 0 deletions src/RNCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type PropsType = ViewPropTypes & {
onTextRecognized?: ({ textBlocks: Array<TrackedTextFeature> }) => void,
captureAudio?: boolean,
useCamera2Api?: boolean,
playSoundOnCapture?: boolean,
};

const CameraManager: Object = NativeModules.RNCameraManager ||
Expand Down Expand Up @@ -154,6 +155,7 @@ export default class Camera extends React.Component<PropsType> {
pendingAuthorizationView: PropTypes.element,
captureAudio: PropTypes.bool,
useCamera2Api: PropTypes.bool,
playSoundOnCapture: PropTypes.bool,
};

static defaultProps: Object = {
Expand Down Expand Up @@ -201,6 +203,7 @@ export default class Camera extends React.Component<PropsType> {
),
captureAudio: false,
useCamera2Api: false,
playSoundOnCapture: false,
};

_cameraRef: ?Object;
Expand Down

0 comments on commit 6924218

Please sign in to comment.