feat: Add enableShutterSound
prop to takePhoto()
🔊 (#1702)
* feat: Add `enableShutterSound` prop to `takePhoto()` 🔊
* Swift lint
This commit is contained in:
@@ -45,6 +45,9 @@ extension CameraView {
|
||||
photoSettings.flashMode = flashMode
|
||||
}
|
||||
|
||||
// shutter sound
|
||||
let enableShutterSound = options["enableShutterSound"] as? Bool ?? true
|
||||
|
||||
// depth data
|
||||
photoSettings.isDepthDataDeliveryEnabled = photoOutput.isDepthDataDeliveryEnabled
|
||||
if #available(iOS 12.0, *) {
|
||||
@@ -75,7 +78,7 @@ extension CameraView {
|
||||
photoSettings.isAutoContentAwareDistortionCorrectionEnabled = enableAutoDistortionCorrection
|
||||
}
|
||||
|
||||
photoOutput.capturePhoto(with: photoSettings, delegate: PhotoCaptureDelegate(promise: promise))
|
||||
photoOutput.capturePhoto(with: photoSettings, delegate: PhotoCaptureDelegate(promise: promise, enableShutterSound: enableShutterSound))
|
||||
|
||||
// Assume that `takePhoto` is always called with the same parameters, so prepare the next call too.
|
||||
photoOutput.setPreparedPhotoSettingsArray([photoSettings], completionHandler: nil)
|
||||
|
@@ -14,13 +14,22 @@ private var delegatesReferences: [NSObject] = []
|
||||
|
||||
class PhotoCaptureDelegate: NSObject, AVCapturePhotoCaptureDelegate {
|
||||
private let promise: Promise
|
||||
private let enableShutterSound: Bool
|
||||
|
||||
required init(promise: Promise) {
|
||||
required init(promise: Promise, enableShutterSound: Bool) {
|
||||
self.promise = promise
|
||||
self.enableShutterSound = enableShutterSound
|
||||
super.init()
|
||||
delegatesReferences.append(self)
|
||||
}
|
||||
|
||||
func photoOutput(_: AVCapturePhotoOutput, willCapturePhotoFor _: AVCaptureResolvedPhotoSettings) {
|
||||
if !enableShutterSound {
|
||||
// disable system shutter sound (see https://stackoverflow.com/a/55235949/5281431)
|
||||
AudioServicesDisposeSystemSoundID(1108)
|
||||
}
|
||||
}
|
||||
|
||||
func photoOutput(_: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
|
||||
defer {
|
||||
delegatesReferences.removeAll(where: { $0 == self })
|
||||
|
Reference in New Issue
Block a user