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

Commit 6924218

Browse files
committed
feat(play-sound): play sound on capture (android)
1 parent b0bd0de commit 6924218

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

android/src/main/java/org/reactnative/camera/CameraViewManager.java

+5
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ public void setUseCamera2Api(RNCameraView view, boolean useCamera2Api) {
120120
view.setUsingCamera2Api(useCamera2Api);
121121
}
122122

123+
@ReactProp(name = "playSoundOnCapture")
124+
public void setPlaySoundOnCapture(RNCameraView view, boolean playSoundOnCapture) {
125+
view.setPlaySoundOnCapture(playSoundOnCapture);
126+
}
127+
123128
@ReactProp(name = "faceDetectorEnabled")
124129
public void setFaceDetecting(RNCameraView view, boolean faceDetectorEnabled) {
125130
view.setShouldDetectFaces(faceDetectorEnabled);

android/src/main/java/org/reactnative/camera/RNCameraView.java

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.pm.PackageManager;
55
import android.graphics.Color;
66
import android.media.CamcorderProfile;
7+
import android.media.MediaActionSound;
78
import android.os.Build;
89
import android.support.v4.content.ContextCompat;
910
import android.util.SparseArray;
@@ -54,6 +55,7 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
5455
private Map<Promise, File> mPictureTakenDirectories = new ConcurrentHashMap<>();
5556
private Promise mVideoRecordedPromise;
5657
private List<String> mBarCodeTypes = null;
58+
private Boolean mPlaySoundOnCapture = false;
5759

5860
private boolean mIsPaused = false;
5961
private boolean mIsNew = true;
@@ -201,10 +203,18 @@ public void setBarCodeTypes(List<String> barCodeTypes) {
201203
initBarcodeReader();
202204
}
203205

206+
public void setPlaySoundOnCapture(Boolean playSoundOnCapture) {
207+
mPlaySoundOnCapture = playSoundOnCapture;
208+
}
209+
204210
public void takePicture(ReadableMap options, final Promise promise, File cacheDirectory) {
205211
mPictureTakenPromises.add(promise);
206212
mPictureTakenOptions.put(promise, options);
207213
mPictureTakenDirectories.put(promise, cacheDirectory);
214+
if (mPlaySoundOnCapture) {
215+
MediaActionSound sound = new MediaActionSound();
216+
sound.play(MediaActionSound.SHUTTER_CLICK);
217+
}
208218
super.takePicture();
209219
}
210220

src/RNCamera.js

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type PropsType = ViewPropTypes & {
7777
onTextRecognized?: ({ textBlocks: Array<TrackedTextFeature> }) => void,
7878
captureAudio?: boolean,
7979
useCamera2Api?: boolean,
80+
playSoundOnCapture?: boolean,
8081
};
8182

8283
const CameraManager: Object = NativeModules.RNCameraManager ||
@@ -154,6 +155,7 @@ export default class Camera extends React.Component<PropsType> {
154155
pendingAuthorizationView: PropTypes.element,
155156
captureAudio: PropTypes.bool,
156157
useCamera2Api: PropTypes.bool,
158+
playSoundOnCapture: PropTypes.bool,
157159
};
158160

159161
static defaultProps: Object = {
@@ -201,6 +203,7 @@ export default class Camera extends React.Component<PropsType> {
201203
),
202204
captureAudio: false,
203205
useCamera2Api: false,
206+
playSoundOnCapture: false,
204207
};
205208

206209
_cameraRef: ?Object;

0 commit comments

Comments
 (0)