@@ -151,6 +151,19 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
151151 photoSettings. flashMode = . off
152152 }
153153
154+ // Ensure proper orientation
155+ if let photoConnection = avPhotoOutput. connection ( with: . video) ,
156+ let previewConnection = videoPreviewLayer. connection {
157+ if photoConnection. isVideoOrientationSupported {
158+ photoConnection. videoOrientation = previewConnection. videoOrientation
159+ }
160+
161+ // Handle mirroring for front camera
162+ if photoConnection. isVideoMirroringSupported && cameraDevice. position == . front {
163+ photoConnection. isVideoMirrored = true
164+ }
165+ }
166+
154167 avPhotoOutput. capturePhoto ( with: photoSettings, delegate: self )
155168 photoCaptureHandler = completion
156169 }
@@ -169,22 +182,25 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
169182 return
170183 }
171184
185+ // Ensure proper orientation
186+ if let photoConnection = avPhotoOutput. connection ( with: . video) ,
187+ let previewConnection = videoPreviewLayer. connection {
188+ if photoConnection. isVideoOrientationSupported {
189+ photoConnection. videoOrientation = previewConnection. videoOrientation
190+ }
191+
192+ // Handle mirroring for front camera
193+ if photoConnection. isVideoMirroringSupported && cameraDevice. position == . front {
194+ photoConnection. isVideoMirrored = true
195+ }
196+ }
197+
172198 // Create a serial queue for sample buffer processing
173199 let sampleBufferQueue = DispatchQueue ( label: " com.michaelwolz.capacitorcameraview.snapshotQueue " )
174200
175201 // Set the delegate for a single frame capture
176202 snapshotCompletionHandler = completion
177203 avVideoDataOutput. setSampleBufferDelegate ( self , queue: sampleBufferQueue)
178-
179- // Ensure proper orientation
180- if let connection = avVideoDataOutput. connection ( with: . video) {
181- if connection. isVideoOrientationSupported {
182- connection. videoOrientation = videoPreviewLayer. connection? . videoOrientation ?? . portrait
183- }
184- if connection. isVideoMirroringSupported && cameraDevice. position == . front {
185- connection. isVideoMirrored = true
186- }
187- }
188204 }
189205
190206 public func setCameraById( _ cameraId: String ) throws {
@@ -572,16 +588,16 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
572588 return
573589 }
574590
575- let orientation = UIDevice . current . orientation
591+ let interfaceOrientation = UIApplication . shared . windows . first ? . windowScene ? . interfaceOrientation ?? . portrait
576592 let videoOrientation : AVCaptureVideoOrientation
577593
578- switch orientation {
594+ switch interfaceOrientation {
579595 case . portrait:
580596 videoOrientation = . portrait
581597 case . landscapeLeft:
582- videoOrientation = . landscapeRight
583- case . landscapeRight:
584598 videoOrientation = . landscapeLeft
599+ case . landscapeRight:
600+ videoOrientation = . landscapeRight
585601 case . portraitUpsideDown:
586602 videoOrientation = . portraitUpsideDown
587603 default :
0 commit comments