@@ -27,6 +27,7 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
2727 public weak var delegate : NSCameraViewDelegate ?
2828 var nextLevel : NextLevel ?
2929 var captureModeCompletionHandler : ( ( ) -> Void ) ?
30+ private var captureModeBeforePhoto : NextLevelCaptureMode = . photo
3031 override init ( frame: CGRect ) {
3132 super. init ( frame: frame )
3233 commonInit ( )
@@ -87,6 +88,25 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
8788 }
8889 }
8990
91+ public var automaticallyUpdatesDeviceOrientation : Bool {
92+ get {
93+ return self . nextLevel? . automaticallyUpdatesDeviceOrientation ?? true
94+ }
95+ set {
96+ self . nextLevel? . automaticallyUpdatesDeviceOrientation = newValue
97+ }
98+ }
99+
100+ public var captureMode : Int {
101+ get {
102+ return ( self . nextLevel? . captureMode ?? NextLevelCaptureMode . photo) . rawValue
103+ }
104+ set {
105+ captureModeBeforePhoto = NextLevelCaptureMode ( rawValue: newValue) !
106+ self . nextLevel? . captureMode = captureModeBeforePhoto
107+ }
108+ }
109+
90110 func commonInit( ) {
91111 self . autoresizingMask = [ . flexibleWidth, . flexibleHeight]
92112 self . backgroundColor = UIColor . black
@@ -117,9 +137,8 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
117137 nextLevel. videoConfiguration. maxKeyFrameInterval = 30
118138 nextLevel. videoConfiguration. profileLevel = AVVideoProfileLevelH264HighAutoLevel
119139
120- // audio configuration
121- // for now disable audio
122- nextLevel. captureMode = NextLevelCaptureMode . videoWithoutAudio
140+ nextLevel. captureMode = NextLevelCaptureMode . photo
141+ nextLevel. photoConfiguration. isHighResolutionEnabled = true
123142 // nextLevel.audioConfiguration.bitRate = 96000
124143 // nextLevel.disableAudioInputDevice()
125144 // metadata objects configuration
@@ -160,23 +179,30 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
160179 return self . nextLevel? . canCaptureVideo ?? false
161180 }
162181 }
182+ public var videoOrientation : Int {
183+ get {
184+ return ( self . nextLevel? . previewLayer. connection? . videoOrientation ?? AVCaptureVideoOrientation . portrait) . rawValue
185+ }
186+ }
163187 public func capturePhoto( _ options: String ) {
164188 if let nextLevel = self . nextLevel , self . canCapturePhoto {
165- if ( nextLevel. captureMode == NextLevelCaptureMode . photo) {
189+ // if ( nextLevel.captureMode == NextLevelCaptureMode.photo) {
166190 nextLevel. capturePhoto ( )
167- } else {
168- captureModeCompletionHandler = {
169- nextLevel. capturePhoto ( )
170- }
171- nextLevel. captureMode = NextLevelCaptureMode . photo
172- }
191+ // } else {
192+ // captureModeBeforePhoto = nextLevel.captureMode
193+ // captureModeCompletionHandler = {
194+ // nextLevel.capturePhoto()
195+ // }
196+ // nextLevel.captureMode = NextLevelCaptureMode.photo
197+ // }
173198 }
174199 }
175200 public func capturePhotoFromVideo( ) {
176201 if let nextLevel = self . nextLevel , self . canCaptureVideo {
177202 if ( nextLevel. captureMode == NextLevelCaptureMode . videoWithoutAudio || nextLevel. captureMode == NextLevelCaptureMode . video) {
178203 nextLevel. capturePhotoFromVideo ( )
179204 } else {
205+ captureModeBeforePhoto = nextLevel. captureMode
180206 captureModeCompletionHandler = {
181207 nextLevel. capturePhotoFromVideo ( )
182208 }
@@ -196,7 +222,18 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
196222 }
197223
198224 public func nextLevelSessionWillStart( _ nextLevel: NextLevel ) {
199-
225+ // DispatchQueue.main.async {
226+ // var uiOrientation: UIInterfaceOrientation = .portrait
227+ //// if #available(iOS 13.0, *) {
228+ //// uiOrientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation ?? UIApplication.shared.statusBarOrientation
229+ //// } else {
230+ // uiOrientation = UIApplication.shared.statusBarOrientation
231+ //// }
232+ //
233+ // let orientation = AVCaptureVideoOrientation.init(rawValue: uiOrientation.rawValue) ?? AVCaptureVideoOrientation.portrait
234+ // nextLevel.previewLayer.connection?.videoOrientation = orientation;
235+ // }
236+
200237 }
201238
202239 public func nextLevelSessionDidStart( _ nextLevel: NextLevel ) {
@@ -221,7 +258,7 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
221258 }
222259
223260 public func nextLevelCaptureModeDidChange( _ nextLevel: NextLevel ) {
224- captureModeCompletionHandler ? ( )
261+ self . captureModeCompletionHandler ? ( )
225262 }
226263
227264 // MARK: NextLevelPhotoDelegate
@@ -288,6 +325,9 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
288325
289326 public func nextLevel( _ nextLevel: NextLevel , didCompletePhotoCaptureFromVideoFrame photoDict: [ String : Any ] ? ) {
290327 self . videoDelegate? . cameraView ( self , didCompletePhotoCaptureFromVideoFrame: photoDict)
328+ if ( captureModeBeforePhoto != nextLevel. captureMode) {
329+ nextLevel. captureMode = captureModeBeforePhoto
330+ }
291331 }
292332
293333 // MARK: NextLevelPhotoDelegate
@@ -308,8 +348,6 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
308348 // Returns corresponting NSCFNumber. It seems to specify the origin of the image
309349 // print("Metadata orientation: ",photoMetadata["Orientation"])
310350
311- // Returns corresponting NSCFNumber. It seems to specify the origin of the image
312- print ( " Metadata orientation with key: " , photoMetadata [ String ( kCGImagePropertyOrientation) ] as Any )
313351
314352 guard let imageData = photo. fileDataRepresentation ( ) else {
315353 print ( " Error while generating image from photo capture data. " ) ;
@@ -335,6 +373,9 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
335373 let image = UIImage ( cgImage: cgImage, scale: 1.0 , orientation: deviceOrientationOnCapture. getUIImageOrientationFromDevice ( ) )
336374
337375 self . photoDelegate? . cameraView ( self , didFinishProcessingPhoto: image, photoDict: photoDict, photoConfiguration: NSCameraViewPhotoConfiguration ( configuration: photoConfiguration) )
376+ if ( captureModeBeforePhoto != nextLevel. captureMode) {
377+ nextLevel. captureMode = captureModeBeforePhoto
378+ }
338379 }
339380
340381 public func nextLevelDidCompletePhotoCapture( _ nextLevel: NextLevel ) {
0 commit comments