feat: Add enableShutterSound prop to takePhoto() 🔊 (#1702)

* feat: Add `enableShutterSound` prop to `takePhoto()` 🔊

* Swift lint
This commit is contained in:
Marc Rousavy
2023-08-21 15:27:42 +02:00
committed by GitHub
parent 0a51980f26
commit a46839a57b
7 changed files with 37 additions and 4 deletions

View File

@@ -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)

View File

@@ -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 })