feat(play-sound): play sound on capture (android)

This commit is contained in:
Joao Fidelis 2018-04-06 14:54:52 -03:00
parent b0bd0de2b3
commit 69242183cc
3 changed files with 18 additions and 0 deletions

View File

@ -120,6 +120,11 @@ public class CameraViewManager extends ViewGroupManager<RNCameraView> {
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);

View File

@ -4,6 +4,7 @@ import android.Manifest;
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;
@ -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;
@ -201,10 +203,18 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
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();
}

View File

@ -77,6 +77,7 @@ type PropsType = ViewPropTypes & {
onTextRecognized?: ({ textBlocks: Array<TrackedTextFeature> }) => void,
captureAudio?: boolean,
useCamera2Api?: boolean,
playSoundOnCapture?: boolean,
};
const CameraManager: Object = NativeModules.RNCameraManager ||
@ -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 = {
@ -201,6 +203,7 @@ export default class Camera extends React.Component<PropsType> {
),
captureAudio: false,
useCamera2Api: false,
playSoundOnCapture: false,
};
_cameraRef: ?Object;