Merge pull request #1441 from react-native-community/feat/play-sound

feat(play-sound): play sound on capture (android)
This commit is contained in:
João Guilherme Fidelis 2018-04-06 15:18:26 -03:00 committed by GitHub
commit a506fda0a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -120,6 +120,11 @@ public class CameraViewManager extends ViewGroupManager<RNCameraView> {
view.setUsingCamera2Api(useCamera2Api); view.setUsingCamera2Api(useCamera2Api);
} }
@ReactProp(name = "playSoundOnCapture")
public void setPlaySoundOnCapture(RNCameraView view, boolean playSoundOnCapture) {
view.setPlaySoundOnCapture(playSoundOnCapture);
}
@ReactProp(name = "faceDetectorEnabled") @ReactProp(name = "faceDetectorEnabled")
public void setFaceDetecting(RNCameraView view, boolean faceDetectorEnabled) { public void setFaceDetecting(RNCameraView view, boolean faceDetectorEnabled) {
view.setShouldDetectFaces(faceDetectorEnabled); view.setShouldDetectFaces(faceDetectorEnabled);

View File

@ -4,6 +4,7 @@ import android.Manifest;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Color; import android.graphics.Color;
import android.media.CamcorderProfile; import android.media.CamcorderProfile;
import android.media.MediaActionSound;
import android.os.Build; import android.os.Build;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.util.SparseArray; import android.util.SparseArray;
@ -54,6 +55,7 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
private Map<Promise, File> mPictureTakenDirectories = new ConcurrentHashMap<>(); private Map<Promise, File> mPictureTakenDirectories = new ConcurrentHashMap<>();
private Promise mVideoRecordedPromise; private Promise mVideoRecordedPromise;
private List<String> mBarCodeTypes = null; private List<String> mBarCodeTypes = null;
private Boolean mPlaySoundOnCapture = false;
private boolean mIsPaused = false; private boolean mIsPaused = false;
private boolean mIsNew = true; private boolean mIsNew = true;
@ -201,10 +203,18 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
initBarcodeReader(); initBarcodeReader();
} }
public void setPlaySoundOnCapture(Boolean playSoundOnCapture) {
mPlaySoundOnCapture = playSoundOnCapture;
}
public void takePicture(ReadableMap options, final Promise promise, File cacheDirectory) { public void takePicture(ReadableMap options, final Promise promise, File cacheDirectory) {
mPictureTakenPromises.add(promise); mPictureTakenPromises.add(promise);
mPictureTakenOptions.put(promise, options); mPictureTakenOptions.put(promise, options);
mPictureTakenDirectories.put(promise, cacheDirectory); mPictureTakenDirectories.put(promise, cacheDirectory);
if (mPlaySoundOnCapture) {
MediaActionSound sound = new MediaActionSound();
sound.play(MediaActionSound.SHUTTER_CLICK);
}
super.takePicture(); super.takePicture();
} }

View File

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