@capacitor-community/camera-preview 2.0.0-beta.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorCommunityCameraPreview.podspec +3 -2
- package/LICENSE +21 -0
- package/README.md +80 -61
- package/android/.gradle/4.10.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/4.10.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/4.10.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/4.10.1/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/compiler.xml +6 -0
- package/android/.idea/gradle.xml +20 -0
- package/android/.idea/jarRepositories.xml +45 -0
- package/android/.idea/libraries/Gradle__androidx_activity_activity_1_2_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_activity_activity_1_2_3_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_annotation_annotation_1_1_0.xml +9 -0
- package/android/.idea/libraries/Gradle__androidx_annotation_annotation_1_2_0.xml +9 -0
- package/android/.idea/libraries/Gradle__androidx_annotation_annotation_experimental_1_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_1_2_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_1_3_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_resources_1_2_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_resources_1_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_arch_core_core_common_2_1_0.xml +9 -0
- package/android/.idea/libraries/Gradle__androidx_arch_core_core_runtime_2_1_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_collection_collection_1_1_0.xml +9 -0
- package/android/.idea/libraries/Gradle__androidx_coordinatorlayout_coordinatorlayout_1_1_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_core_core_1_3_2_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_core_core_1_5_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_cursoradapter_cursoradapter_1_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_customview_customview_1_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_drawerlayout_drawerlayout_1_0_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_exifinterface_exifinterface_1_3_2_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_fragment_fragment_1_3_0_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_fragment_fragment_1_3_4_aar.xml +14 -0
- package/android/.idea/libraries/Gradle__androidx_interpolator_interpolator_1_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_common_2_3_0.xml +9 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_common_2_3_1.xml +9 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_2_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_core_2_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_core_2_3_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_runtime_2_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_runtime_2_3_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_2_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_2_3_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_savedstate_2_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_savedstate_2_3_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_loader_loader_1_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_savedstate_savedstate_1_1_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_core_1_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_espresso_espresso_core_3_1_0_alpha3_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_espresso_espresso_core_3_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_espresso_espresso_idling_resource_3_1_0_alpha3_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_espresso_espresso_idling_resource_3_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_ext_junit_1_1_2_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_monitor_1_1_0_alpha3_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_monitor_1_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_runner_1_1_0_alpha3_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_test_runner_1_3_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_tracing_tracing_1_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_1_1_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_animated_1_1_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_versionedparcelable_versionedparcelable_1_1_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_versionedparcelable_versionedparcelable_1_1_1_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__androidx_viewpager_viewpager_1_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_2_0_1.xml +9 -0
- package/android/.idea/libraries/Gradle__com_squareup_javawriter_2_1_1.xml +9 -0
- package/android/.idea/libraries/Gradle__javax_inject_javax_inject_1.xml +9 -0
- package/android/.idea/libraries/Gradle__junit_junit_4_12.xml +9 -0
- package/android/.idea/libraries/Gradle__junit_junit_4_13_1.xml +9 -0
- package/android/.idea/libraries/Gradle__net_bytebuddy_byte_buddy_1_10_18.xml +9 -0
- package/android/.idea/libraries/Gradle__net_bytebuddy_byte_buddy_agent_1_10_18.xml +9 -0
- package/android/.idea/libraries/Gradle__net_sf_kxml_kxml2_2_3_0.xml +9 -0
- package/android/.idea/libraries/Gradle__org_apache_cordova_framework_7_0_0_aar.xml +11 -0
- package/android/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml +9 -0
- package/android/.idea/libraries/Gradle__org_hamcrest_hamcrest_integration_1_3.xml +9 -0
- package/android/.idea/libraries/Gradle__org_hamcrest_hamcrest_library_1_3.xml +9 -0
- package/android/.idea/libraries/Gradle__org_json_json_20140107.xml +9 -0
- package/android/.idea/libraries/Gradle__org_mockito_mockito_core_3_6_28.xml +9 -0
- package/android/.idea/libraries/Gradle__org_mockito_mockito_inline_3_6_28.xml +9 -0
- package/android/.idea/libraries/Gradle__org_objenesis_objenesis_3_1.xml +9 -0
- package/android/.idea/misc.xml +9 -0
- package/android/.idea/modules/1419750366/android.capacitor-android.iml +92 -0
- package/android/.idea/modules/android.iml +87 -0
- package/android/.idea/modules.xml +9 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/build.gradle +4 -4
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +128 -70
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +163 -118
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomTextureView.java +31 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/Preview.java +96 -19
- package/dist/esm/definitions.d.ts +18 -5
- package/dist/esm/definitions.js +1 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +8 -1
- package/dist/esm/web.js +95 -77
- package/dist/esm/web.js.map +1 -1
- package/ios/Plugin/CameraController.swift +237 -48
- package/ios/Plugin/Plugin.m +3 -0
- package/ios/Plugin/Plugin.swift +130 -46
- package/ios/Plugin.xcodeproj/project.pbxproj +2 -6
- package/ios/Podfile +2 -2
- package/ios/Podfile.lock +4 -4
- package/package.json +7 -6
- package/android/local.properties +0 -8
- package/ios/Plugin.xcodeproj/xcuserdata/ahernandez.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- package/ios/Plugin.xcodeproj/xcuserdata/nielsvanharen.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- package/ios/Plugin.xcworkspace/xcuserdata/ahernandez.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Plugin.xcworkspace/xcuserdata/arielhernandezmusa.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Plugin.xcworkspace/xcuserdata/nielsvanharen.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Pods/CapacitorCordova/LICENSE +0 -23
- package/ios/Pods/CapacitorCordova/README.md +0 -39
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/CapacitorCordova.h +0 -21
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/AppDelegate.h +0 -8
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/AppDelegate.m +0 -5
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDV.h +0 -28
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVAvailability.h +0 -109
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegate.h +0 -51
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegateImpl.h +0 -39
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegateImpl.m +0 -154
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVConfigParser.h +0 -31
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVConfigParser.m +0 -81
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVInvokedUrlCommand.h +0 -52
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVInvokedUrlCommand.m +0 -116
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin.h +0 -81
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin.m +0 -154
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginManager.h +0 -25
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginManager.m +0 -77
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginResult.h +0 -82
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginResult.m +0 -216
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVScreenOrientationDelegate.h +0 -33
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUIWebViewDelegate.h +0 -41
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUIWebViewDelegate.m +0 -399
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVURLProtocol.h +0 -27
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVURLProtocol.m +0 -74
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUserAgentUtil.h +0 -27
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVUserAgentUtil.m +0 -156
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVViewController.h +0 -30
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/CDVViewController.m +0 -34
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/NSDictionary+CordovaPreferences.h +0 -35
- package/ios/Pods/CapacitorCordova/ios/CapacitorCordova/CapacitorCordova/Classes/Public/NSDictionary+CordovaPreferences.m +0 -63
- package/ios/Pods/Local Podspecs/Capacitor.podspec.json +0 -31
- package/ios/Pods/Manifest.lock +0 -23
- package/ios/Pods/Pods.xcodeproj/project.pbxproj +0 -1296
- package/ios/Pods/Pods.xcodeproj/xcuserdata/ahernandez.xcuserdatad/xcschemes/Capacitor.xcscheme +0 -60
- package/ios/Pods/Pods.xcodeproj/xcuserdata/ahernandez.xcuserdatad/xcschemes/CapacitorCordova.xcscheme +0 -58
- package/ios/Pods/Pods.xcodeproj/xcuserdata/ahernandez.xcuserdatad/xcschemes/Pods-Plugin.xcscheme +0 -58
- package/ios/Pods/Pods.xcodeproj/xcuserdata/ahernandez.xcuserdatad/xcschemes/Pods-PluginTests.xcscheme +0 -58
- package/ios/Pods/Pods.xcodeproj/xcuserdata/ahernandez.xcuserdatad/xcschemes/xcschememanagement.plist +0 -39
- package/ios/Pods/Target Support Files/Capacitor/Capacitor-Info.plist +0 -26
- package/ios/Pods/Target Support Files/Capacitor/Capacitor-dummy.m +0 -5
- package/ios/Pods/Target Support Files/Capacitor/Capacitor-prefix.pch +0 -12
- package/ios/Pods/Target Support Files/Capacitor/Capacitor.debug.xcconfig +0 -13
- package/ios/Pods/Target Support Files/Capacitor/Capacitor.modulemap +0 -7
- package/ios/Pods/Target Support Files/Capacitor/Capacitor.release.xcconfig +0 -13
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-Info.plist +0 -26
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-dummy.m +0 -5
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-prefix.pch +0 -12
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova-umbrella.h +0 -32
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.debug.xcconfig +0 -12
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.modulemap +0 -6
- package/ios/Pods/Target Support Files/CapacitorCordova/CapacitorCordova.release.xcconfig +0 -12
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-Info.plist +0 -26
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-acknowledgements.markdown +0 -57
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-acknowledgements.plist +0 -95
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-dummy.m +0 -5
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin-umbrella.h +0 -16
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.debug.xcconfig +0 -13
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.modulemap +0 -6
- package/ios/Pods/Target Support Files/Pods-Plugin/Pods-Plugin.release.xcconfig +0 -13
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-Info.plist +0 -26
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-acknowledgements.markdown +0 -57
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-acknowledgements.plist +0 -95
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-dummy.m +0 -5
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-frameworks.sh +0 -187
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-umbrella.h +0 -16
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.debug.xcconfig +0 -14
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.modulemap +0 -6
- package/ios/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.release.xcconfig +0 -14
|
@@ -17,6 +17,7 @@ class CameraController: NSObject {
|
|
|
17
17
|
var frontCamera: AVCaptureDevice?
|
|
18
18
|
var frontCameraInput: AVCaptureDeviceInput?
|
|
19
19
|
|
|
20
|
+
var dataOutput: AVCaptureVideoDataOutput?
|
|
20
21
|
var photoOutput: AVCapturePhotoOutput?
|
|
21
22
|
|
|
22
23
|
var rearCamera: AVCaptureDevice?
|
|
@@ -27,7 +28,14 @@ class CameraController: NSObject {
|
|
|
27
28
|
var flashMode = AVCaptureDevice.FlashMode.off
|
|
28
29
|
var photoCaptureCompletionBlock: ((UIImage?, Error?) -> Void)?
|
|
29
30
|
|
|
31
|
+
var sampleBufferCaptureCompletionBlock: ((UIImage?, Error?) -> Void)?
|
|
32
|
+
|
|
30
33
|
var highResolutionOutput: Bool = false
|
|
34
|
+
|
|
35
|
+
var audioDevice: AVCaptureDevice?
|
|
36
|
+
var audioInput: AVCaptureDeviceInput?
|
|
37
|
+
|
|
38
|
+
var zoomFactor: CGFloat = 1.0
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
extension CameraController {
|
|
@@ -56,6 +64,7 @@ extension CameraController {
|
|
|
56
64
|
camera.unlockForConfiguration()
|
|
57
65
|
}
|
|
58
66
|
}
|
|
67
|
+
self.audioDevice = AVCaptureDevice.default(for: AVMediaType.audio)
|
|
59
68
|
}
|
|
60
69
|
|
|
61
70
|
func configureDeviceInputs() throws {
|
|
@@ -79,6 +88,16 @@ extension CameraController {
|
|
|
79
88
|
self.currentCameraPosition = .front
|
|
80
89
|
}
|
|
81
90
|
} else { throw CameraControllerError.noCamerasAvailable }
|
|
91
|
+
|
|
92
|
+
// Add audio input
|
|
93
|
+
if let audioDevice = self.audioDevice {
|
|
94
|
+
self.audioInput = try AVCaptureDeviceInput(device: audioDevice)
|
|
95
|
+
if captureSession.canAddInput(self.audioInput!) {
|
|
96
|
+
captureSession.addInput(self.audioInput!)
|
|
97
|
+
} else {
|
|
98
|
+
throw CameraControllerError.inputsAreInvalid
|
|
99
|
+
}
|
|
100
|
+
}
|
|
82
101
|
}
|
|
83
102
|
|
|
84
103
|
func configurePhotoOutput() throws {
|
|
@@ -91,12 +110,32 @@ extension CameraController {
|
|
|
91
110
|
captureSession.startRunning()
|
|
92
111
|
}
|
|
93
112
|
|
|
113
|
+
func configureDataOutput() throws {
|
|
114
|
+
guard let captureSession = self.captureSession else { throw CameraControllerError.captureSessionIsMissing }
|
|
115
|
+
|
|
116
|
+
self.dataOutput = AVCaptureVideoDataOutput()
|
|
117
|
+
self.dataOutput?.videoSettings = [
|
|
118
|
+
(kCVPixelBufferPixelFormatTypeKey as String): NSNumber(value: kCVPixelFormatType_32BGRA as UInt32)
|
|
119
|
+
]
|
|
120
|
+
self.dataOutput?.alwaysDiscardsLateVideoFrames = true
|
|
121
|
+
if captureSession.canAddOutput(self.dataOutput!) {
|
|
122
|
+
captureSession.addOutput(self.dataOutput!)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
captureSession.commitConfiguration()
|
|
126
|
+
|
|
127
|
+
let queue = DispatchQueue(label: "DataOutput", attributes: [])
|
|
128
|
+
self.dataOutput?.setSampleBufferDelegate(self, queue: queue)
|
|
129
|
+
}
|
|
130
|
+
|
|
94
131
|
DispatchQueue(label: "prepare").async {
|
|
95
132
|
do {
|
|
96
133
|
createCaptureSession()
|
|
97
134
|
try configureCaptureDevices()
|
|
98
135
|
try configureDeviceInputs()
|
|
99
136
|
try configurePhotoOutput()
|
|
137
|
+
try configureDataOutput()
|
|
138
|
+
//try configureVideoOutput()
|
|
100
139
|
}
|
|
101
140
|
|
|
102
141
|
catch {
|
|
@@ -108,6 +147,8 @@ extension CameraController {
|
|
|
108
147
|
}
|
|
109
148
|
|
|
110
149
|
DispatchQueue.main.async {
|
|
150
|
+
self.updateVideoOrientation()
|
|
151
|
+
|
|
111
152
|
completionHandler(nil)
|
|
112
153
|
}
|
|
113
154
|
}
|
|
@@ -119,36 +160,63 @@ extension CameraController {
|
|
|
119
160
|
self.previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
|
|
120
161
|
self.previewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
|
|
121
162
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
163
|
+
view.layer.insertSublayer(self.previewLayer!, at: 0)
|
|
164
|
+
self.previewLayer?.frame = view.frame
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
func setupGestures(target: UIView, enableZoom: Bool) {
|
|
168
|
+
setupTapGesture(target: target, selector: #selector(handleTap(_:)), delegate: self)
|
|
169
|
+
if (enableZoom) {
|
|
170
|
+
setupPinchGesture(target: target, selector: #selector(handlePinch(_:)), delegate: self)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
func setupTapGesture(target: UIView, selector: Selector, delegate: UIGestureRecognizerDelegate?) {
|
|
175
|
+
let tapGesture = UITapGestureRecognizer(target: self, action: selector)
|
|
176
|
+
tapGesture.delegate = delegate
|
|
177
|
+
target.addGestureRecognizer(tapGesture)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
func setupPinchGesture(target: UIView, selector: Selector, delegate: UIGestureRecognizerDelegate?) {
|
|
181
|
+
let pinchGesture = UIPinchGestureRecognizer(target: self, action: selector)
|
|
182
|
+
pinchGesture.delegate = delegate
|
|
183
|
+
target.addGestureRecognizer(pinchGesture)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
func updateVideoOrientation() {
|
|
187
|
+
assert(Thread.isMainThread) // UIApplication.statusBarOrientation requires the main thread.
|
|
188
|
+
|
|
189
|
+
let videoOrientation: AVCaptureVideoOrientation
|
|
190
|
+
switch UIDevice.current.orientation {
|
|
125
191
|
case .portrait:
|
|
126
|
-
|
|
127
|
-
case .landscapeRight:
|
|
128
|
-
self.previewLayer?.connection?.videoOrientation = .landscapeLeft
|
|
192
|
+
videoOrientation = .portrait
|
|
129
193
|
case .landscapeLeft:
|
|
130
|
-
|
|
194
|
+
videoOrientation = .landscapeRight
|
|
195
|
+
case .landscapeRight:
|
|
196
|
+
videoOrientation = .landscapeLeft
|
|
131
197
|
case .portraitUpsideDown:
|
|
132
|
-
|
|
133
|
-
case .faceUp, .faceDown:
|
|
134
|
-
|
|
198
|
+
videoOrientation = .portraitUpsideDown
|
|
199
|
+
case .faceUp, .faceDown, .unknown:
|
|
200
|
+
fallthrough
|
|
201
|
+
@unknown default:
|
|
202
|
+
switch UIApplication.shared.statusBarOrientation {
|
|
135
203
|
case .portrait:
|
|
136
|
-
|
|
137
|
-
case .landscapeRight:
|
|
138
|
-
self.previewLayer?.connection?.videoOrientation = .landscapeRight
|
|
204
|
+
videoOrientation = .portrait
|
|
139
205
|
case .landscapeLeft:
|
|
140
|
-
|
|
206
|
+
videoOrientation = .landscapeLeft
|
|
207
|
+
case .landscapeRight:
|
|
208
|
+
videoOrientation = .landscapeRight
|
|
141
209
|
case .portraitUpsideDown:
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
210
|
+
videoOrientation = .portraitUpsideDown
|
|
211
|
+
case .unknown:
|
|
212
|
+
fallthrough
|
|
213
|
+
@unknown default:
|
|
214
|
+
videoOrientation = .portrait
|
|
145
215
|
}
|
|
146
|
-
default:
|
|
147
|
-
self.previewLayer?.connection?.videoOrientation = .portrait
|
|
148
216
|
}
|
|
149
217
|
|
|
150
|
-
|
|
151
|
-
|
|
218
|
+
previewLayer?.connection?.videoOrientation = videoOrientation
|
|
219
|
+
dataOutput?.connections.forEach { $0.videoOrientation = videoOrientation }
|
|
152
220
|
}
|
|
153
221
|
|
|
154
222
|
func switchCameras() throws {
|
|
@@ -212,36 +280,19 @@ extension CameraController {
|
|
|
212
280
|
settings.flashMode = self.flashMode
|
|
213
281
|
settings.isHighResolutionPhotoEnabled = self.highResolutionOutput;
|
|
214
282
|
|
|
215
|
-
let currentDevice: UIDevice = .current
|
|
216
|
-
let deviceOrientation: UIDeviceOrientation = currentDevice.orientation
|
|
217
|
-
let statusBarOrientation = UIApplication.shared.statusBarOrientation
|
|
218
|
-
if deviceOrientation == .portrait {
|
|
219
|
-
self.photoOutput?.connection(with: AVMediaType.video)?.videoOrientation = AVCaptureVideoOrientation.portrait
|
|
220
|
-
}else if (deviceOrientation == .landscapeLeft){
|
|
221
|
-
self.photoOutput?.connection(with: AVMediaType.video)?.videoOrientation = AVCaptureVideoOrientation.landscapeRight
|
|
222
|
-
}else if (deviceOrientation == .landscapeRight){
|
|
223
|
-
self.photoOutput?.connection(with: AVMediaType.video)?.videoOrientation = AVCaptureVideoOrientation.landscapeLeft
|
|
224
|
-
}else if (deviceOrientation == .portraitUpsideDown){
|
|
225
|
-
self.photoOutput?.connection(with: AVMediaType.video)?.videoOrientation = AVCaptureVideoOrientation.portraitUpsideDown
|
|
226
|
-
}else if (deviceOrientation == .faceUp || deviceOrientation == .faceDown){
|
|
227
|
-
switch (statusBarOrientation) {
|
|
228
|
-
case .portrait:
|
|
229
|
-
self.photoOutput?.connection(with: AVMediaType.video)?.videoOrientation = AVCaptureVideoOrientation.portrait
|
|
230
|
-
case .landscapeRight:
|
|
231
|
-
self.photoOutput?.connection(with: AVMediaType.video)?.videoOrientation = AVCaptureVideoOrientation.landscapeRight
|
|
232
|
-
case .landscapeLeft:
|
|
233
|
-
self.photoOutput?.connection(with: AVMediaType.video)?.videoOrientation = AVCaptureVideoOrientation.landscapeLeft
|
|
234
|
-
case .portraitUpsideDown:
|
|
235
|
-
self.photoOutput?.connection(with: AVMediaType.video)?.videoOrientation = AVCaptureVideoOrientation.portraitUpsideDown
|
|
236
|
-
default:
|
|
237
|
-
self.photoOutput?.connection(with: AVMediaType.video)?.videoOrientation = AVCaptureVideoOrientation.portrait
|
|
238
|
-
}
|
|
239
|
-
}else {
|
|
240
|
-
self.photoOutput?.connection(with: AVMediaType.video)?.videoOrientation = AVCaptureVideoOrientation.portrait
|
|
241
|
-
}
|
|
242
283
|
self.photoOutput?.capturePhoto(with: settings, delegate: self)
|
|
243
284
|
self.photoCaptureCompletionBlock = completion
|
|
244
285
|
}
|
|
286
|
+
|
|
287
|
+
func captureSample(completion: @escaping (UIImage?, Error?) -> Void) {
|
|
288
|
+
guard let captureSession = captureSession,
|
|
289
|
+
captureSession.isRunning else {
|
|
290
|
+
completion(nil, CameraControllerError.captureSessionIsMissing)
|
|
291
|
+
return
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
self.sampleBufferCaptureCompletionBlock = completion
|
|
295
|
+
}
|
|
245
296
|
|
|
246
297
|
func getSupportedFlashModes() throws -> [String] {
|
|
247
298
|
var currentCamera: AVCaptureDevice?
|
|
@@ -359,6 +410,92 @@ extension CameraController {
|
|
|
359
410
|
}
|
|
360
411
|
|
|
361
412
|
}
|
|
413
|
+
|
|
414
|
+
func captureVideo(completion: @escaping (URL?, Error?) -> Void) {
|
|
415
|
+
guard let captureSession = self.captureSession, captureSession.isRunning else {
|
|
416
|
+
completion(nil, CameraControllerError.captureSessionIsMissing)
|
|
417
|
+
return
|
|
418
|
+
}
|
|
419
|
+
let path = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
|
|
420
|
+
let identifier = UUID()
|
|
421
|
+
let randomIdentifier = identifier.uuidString.replacingOccurrences(of: "-", with: "")
|
|
422
|
+
let finalIdentifier = String(randomIdentifier.prefix(8))
|
|
423
|
+
let fileName="cpcp_video_"+finalIdentifier+".mp4"
|
|
424
|
+
|
|
425
|
+
let fileUrl = path.appendingPathComponent(fileName)
|
|
426
|
+
try? FileManager.default.removeItem(at: fileUrl)
|
|
427
|
+
/*videoOutput!.startRecording(to: fileUrl, recordingDelegate: self)
|
|
428
|
+
self.videoRecordCompletionBlock = completion*/
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
func stopRecording(completion: @escaping (Error?) -> Void) {
|
|
432
|
+
guard let captureSession = self.captureSession, captureSession.isRunning else {
|
|
433
|
+
completion(CameraControllerError.captureSessionIsMissing)
|
|
434
|
+
return
|
|
435
|
+
}
|
|
436
|
+
//self.videoOutput?.stopRecording()
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
extension CameraController: UIGestureRecognizerDelegate {
|
|
441
|
+
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
@objc
|
|
446
|
+
func handleTap(_ tap: UITapGestureRecognizer) {
|
|
447
|
+
guard let device = self.currentCameraPosition == .rear ? rearCamera : frontCamera else { return }
|
|
448
|
+
|
|
449
|
+
let point = tap.location(in: tap.view)
|
|
450
|
+
let devicePoint = self.previewLayer?.captureDevicePointConverted(fromLayerPoint: point)
|
|
451
|
+
|
|
452
|
+
do {
|
|
453
|
+
try device.lockForConfiguration()
|
|
454
|
+
defer { device.unlockForConfiguration() }
|
|
455
|
+
|
|
456
|
+
let focusMode = AVCaptureDevice.FocusMode.autoFocus
|
|
457
|
+
if device.isFocusPointOfInterestSupported && device.isFocusModeSupported(focusMode) {
|
|
458
|
+
device.focusPointOfInterest = CGPoint(x: CGFloat(devicePoint?.x ?? 0), y: CGFloat(devicePoint?.y ?? 0))
|
|
459
|
+
device.focusMode = focusMode
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
let exposureMode = AVCaptureDevice.ExposureMode.autoExpose
|
|
463
|
+
if device.isExposurePointOfInterestSupported && device.isExposureModeSupported(exposureMode) {
|
|
464
|
+
device.exposurePointOfInterest = CGPoint(x: CGFloat(devicePoint?.x ?? 0), y: CGFloat(devicePoint?.y ?? 0))
|
|
465
|
+
device.exposureMode = exposureMode
|
|
466
|
+
}
|
|
467
|
+
} catch {
|
|
468
|
+
debugPrint(error)
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
@objc
|
|
473
|
+
private func handlePinch(_ pinch: UIPinchGestureRecognizer) {
|
|
474
|
+
guard let device = self.currentCameraPosition == .rear ? rearCamera : frontCamera else { return }
|
|
475
|
+
|
|
476
|
+
func minMaxZoom(_ factor: CGFloat) -> CGFloat { return max(1.0, min(factor, device.activeFormat.videoMaxZoomFactor)) }
|
|
477
|
+
|
|
478
|
+
func update(scale factor: CGFloat) {
|
|
479
|
+
do {
|
|
480
|
+
try device.lockForConfiguration()
|
|
481
|
+
defer { device.unlockForConfiguration() }
|
|
482
|
+
|
|
483
|
+
device.videoZoomFactor = factor
|
|
484
|
+
} catch {
|
|
485
|
+
debugPrint(error)
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
switch pinch.state {
|
|
490
|
+
case .began: fallthrough
|
|
491
|
+
case .changed:
|
|
492
|
+
let newScaleFactor = minMaxZoom(pinch.scale * zoomFactor)
|
|
493
|
+
update(scale: newScaleFactor)
|
|
494
|
+
case .ended:
|
|
495
|
+
zoomFactor = device.videoZoomFactor
|
|
496
|
+
default: break
|
|
497
|
+
}
|
|
498
|
+
}
|
|
362
499
|
}
|
|
363
500
|
|
|
364
501
|
extension CameraController: AVCapturePhotoCaptureDelegate {
|
|
@@ -377,6 +514,48 @@ extension CameraController: AVCapturePhotoCaptureDelegate {
|
|
|
377
514
|
}
|
|
378
515
|
}
|
|
379
516
|
|
|
517
|
+
extension CameraController: AVCaptureVideoDataOutputSampleBufferDelegate {
|
|
518
|
+
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
|
|
519
|
+
guard let completion = sampleBufferCaptureCompletionBlock else { return }
|
|
520
|
+
|
|
521
|
+
guard let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
|
|
522
|
+
completion(nil, CameraControllerError.unknown)
|
|
523
|
+
return
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
CVPixelBufferLockBaseAddress(imageBuffer, .readOnly)
|
|
527
|
+
defer { CVPixelBufferUnlockBaseAddress(imageBuffer, .readOnly) }
|
|
528
|
+
|
|
529
|
+
let baseAddress = CVPixelBufferGetBaseAddress(imageBuffer)
|
|
530
|
+
let bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer)
|
|
531
|
+
let width = CVPixelBufferGetWidth(imageBuffer)
|
|
532
|
+
let height = CVPixelBufferGetHeight(imageBuffer)
|
|
533
|
+
let colorSpace = CGColorSpaceCreateDeviceRGB()
|
|
534
|
+
let bitmapInfo: UInt32 = CGBitmapInfo.byteOrder32Little.rawValue |
|
|
535
|
+
CGImageAlphaInfo.premultipliedFirst.rawValue
|
|
536
|
+
|
|
537
|
+
let context = CGContext(
|
|
538
|
+
data: baseAddress,
|
|
539
|
+
width: width,
|
|
540
|
+
height: height,
|
|
541
|
+
bitsPerComponent: 8,
|
|
542
|
+
bytesPerRow: bytesPerRow,
|
|
543
|
+
space: colorSpace,
|
|
544
|
+
bitmapInfo: bitmapInfo
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
guard let cgImage = context?.makeImage() else {
|
|
548
|
+
completion(nil, CameraControllerError.unknown)
|
|
549
|
+
return
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
let image = UIImage(cgImage: cgImage)
|
|
553
|
+
completion(image.fixedOrientation(), nil)
|
|
554
|
+
|
|
555
|
+
sampleBufferCaptureCompletionBlock = nil
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
380
559
|
|
|
381
560
|
|
|
382
561
|
|
|
@@ -479,3 +658,13 @@ extension UIImage {
|
|
|
479
658
|
return UIImage.init(cgImage: newCGImage, scale: 1, orientation: .up)
|
|
480
659
|
}
|
|
481
660
|
}
|
|
661
|
+
|
|
662
|
+
extension CameraController: AVCaptureFileOutputRecordingDelegate {
|
|
663
|
+
func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {
|
|
664
|
+
/*if error == nil {
|
|
665
|
+
self.videoRecordCompletionBlock?(outputFileURL, nil)
|
|
666
|
+
} else {
|
|
667
|
+
self.videoRecordCompletionBlock?(nil, error)
|
|
668
|
+
}*/
|
|
669
|
+
}
|
|
670
|
+
}
|
package/ios/Plugin/Plugin.m
CHANGED
|
@@ -7,7 +7,10 @@ CAP_PLUGIN(CameraPreview, "CameraPreview",
|
|
|
7
7
|
CAP_PLUGIN_METHOD(start, CAPPluginReturnPromise);
|
|
8
8
|
CAP_PLUGIN_METHOD(stop, CAPPluginReturnPromise);
|
|
9
9
|
CAP_PLUGIN_METHOD(capture, CAPPluginReturnPromise);
|
|
10
|
+
CAP_PLUGIN_METHOD(captureSample, CAPPluginReturnPromise);
|
|
10
11
|
CAP_PLUGIN_METHOD(flip, CAPPluginReturnPromise);
|
|
11
12
|
CAP_PLUGIN_METHOD(getSupportedFlashModes, CAPPluginReturnPromise);
|
|
12
13
|
CAP_PLUGIN_METHOD(setFlashMode, CAPPluginReturnPromise);
|
|
14
|
+
CAP_PLUGIN_METHOD(startRecordVideo, CAPPluginReturnPromise);
|
|
15
|
+
CAP_PLUGIN_METHOD(stopRecordVideo, CAPPluginReturnPromise);
|
|
13
16
|
)
|
package/ios/Plugin/Plugin.swift
CHANGED
|
@@ -19,31 +19,40 @@ public class CameraPreview: CAPPlugin {
|
|
|
19
19
|
var rotateWhenOrientationChanged: Bool?
|
|
20
20
|
var toBack: Bool?
|
|
21
21
|
var storeToFile: Bool?
|
|
22
|
+
var enableZoom: Bool?
|
|
22
23
|
var highResolutionOutput: Bool = false
|
|
23
24
|
|
|
24
25
|
@objc func rotated() {
|
|
25
26
|
|
|
26
|
-
let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!;
|
|
27
|
-
|
|
28
27
|
if UIDevice.current.orientation.isLandscape {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (UIDevice.current.orientation == UIDeviceOrientation.landscapeRight) {
|
|
38
|
-
self.cameraController.previewLayer?.connection?.videoOrientation = .landscapeLeft
|
|
28
|
+
if(self.width! > self.height!) {
|
|
29
|
+
// we started in landscape
|
|
30
|
+
let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!;
|
|
31
|
+
self.previewView.frame = CGRect(x: self.x!, y: self.y!, width: self.width!, height: height)
|
|
32
|
+
} else {
|
|
33
|
+
// we started in portrait
|
|
34
|
+
let width = self.paddingBottom != nil ? self.width! - self.paddingBottom!: self.width!;
|
|
35
|
+
self.previewView.frame = CGRect(x: self.y!, y: self.x!, width: self.height!, height: width)
|
|
39
36
|
}
|
|
37
|
+
self.cameraController.previewLayer?.frame = self.previewView.frame
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
if UIDevice.current.orientation.isPortrait {
|
|
43
|
-
self.previewView
|
|
41
|
+
if (self.previewView != nil && self.x != nil && self.y != nil && self.width != nil && self.height != nil) {
|
|
42
|
+
if(self.height! > self.width!) {
|
|
43
|
+
// we started in portrait
|
|
44
|
+
let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!;
|
|
45
|
+
self.previewView.frame = CGRect(x: self.x!, y: self.y!, width: self.width!, height: height)
|
|
46
|
+
} else {
|
|
47
|
+
// we started in landscape
|
|
48
|
+
let width = self.paddingBottom != nil ? self.width! - self.paddingBottom!: self.width!;
|
|
49
|
+
self.previewView.frame = CGRect(x: self.y!, y: self.x!, width: self.height!, height: width)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
44
52
|
self.cameraController.previewLayer?.frame = self.previewView.frame
|
|
45
|
-
self.cameraController.previewLayer?.connection?.videoOrientation = .portrait
|
|
46
53
|
}
|
|
54
|
+
|
|
55
|
+
cameraController.updateVideoOrientation()
|
|
47
56
|
}
|
|
48
57
|
|
|
49
58
|
@objc func start(_ call: CAPPluginCall) {
|
|
@@ -67,44 +76,52 @@ public class CameraPreview: CAPPlugin {
|
|
|
67
76
|
self.paddingBottom = CGFloat(call.getInt("paddingBottom")!)
|
|
68
77
|
}
|
|
69
78
|
|
|
70
|
-
AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) in
|
|
71
|
-
if (!granted) {
|
|
72
|
-
call.reject("permission failed");
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
79
|
self.rotateWhenOrientationChanged = call.getBool("rotateWhenOrientationChanged") ?? true
|
|
77
80
|
self.toBack = call.getBool("toBack") ?? false
|
|
78
81
|
self.storeToFile = call.getBool("storeToFile") ?? false
|
|
82
|
+
self.enableZoom = call.getBool("enableZoom") ?? false
|
|
79
83
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
self.webView?.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
84
|
+
AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) in
|
|
85
|
+
guard granted else {
|
|
86
|
+
call.reject("permission failed");
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
DispatchQueue.main.async {
|
|
91
|
+
if (self.cameraController.captureSession?.isRunning ?? false) {
|
|
92
|
+
call.reject("camera already started")
|
|
93
|
+
} else {
|
|
94
|
+
self.cameraController.prepare(cameraPosition: self.cameraPosition){error in
|
|
95
|
+
if let error = error {
|
|
96
|
+
print(error)
|
|
97
|
+
call.reject(error.localizedDescription)
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!;
|
|
101
|
+
self.previewView = UIView(frame: CGRect(x: self.x ?? 0, y: self.y ?? 0, width: self.width!, height: height))
|
|
102
|
+
self.webView?.isOpaque = false
|
|
103
|
+
self.webView?.backgroundColor = UIColor.clear
|
|
104
|
+
self.webView?.scrollView.backgroundColor = UIColor.clear
|
|
105
|
+
self.webView?.superview?.addSubview(self.previewView)
|
|
106
|
+
if (self.toBack!) {
|
|
107
|
+
self.webView?.superview?.bringSubviewToFront(self.webView!)
|
|
108
|
+
}
|
|
109
|
+
try? self.cameraController.displayPreview(on: self.previewView)
|
|
110
|
+
|
|
111
|
+
let frontView = self.toBack! ? self.webView : self.previewView;
|
|
112
|
+
self.cameraController.setupGestures(target: frontView ?? self.previewView, enableZoom: self.enableZoom!)
|
|
113
|
+
|
|
114
|
+
if (self.rotateWhenOrientationChanged == true) {
|
|
115
|
+
NotificationCenter.default.addObserver(self, selector: #selector(CameraPreview.rotated), name: UIDevice.orientationDidChangeNotification, object: nil)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
call.resolve()
|
|
104
119
|
|
|
120
|
+
}
|
|
105
121
|
}
|
|
106
122
|
}
|
|
107
|
-
}
|
|
123
|
+
});
|
|
124
|
+
|
|
108
125
|
}
|
|
109
126
|
|
|
110
127
|
@objc func flip(_ call: CAPPluginCall) {
|
|
@@ -156,7 +173,7 @@ public class CameraPreview: CAPPlugin {
|
|
|
156
173
|
return
|
|
157
174
|
}
|
|
158
175
|
let imageData: Data?
|
|
159
|
-
if (self.
|
|
176
|
+
if (self.cameraController.currentCameraPosition == .front) {
|
|
160
177
|
let flippedImage = image.withHorizontallyFlippedOrientation()
|
|
161
178
|
imageData = flippedImage.jpegData(compressionQuality: CGFloat(quality!/100))
|
|
162
179
|
} else {
|
|
@@ -178,6 +195,41 @@ public class CameraPreview: CAPPlugin {
|
|
|
178
195
|
}
|
|
179
196
|
}
|
|
180
197
|
}
|
|
198
|
+
|
|
199
|
+
@objc func captureSample(_ call: CAPPluginCall) {
|
|
200
|
+
DispatchQueue.main.async {
|
|
201
|
+
let quality: Int? = call.getInt("quality", 85)
|
|
202
|
+
|
|
203
|
+
self.cameraController.captureSample { image, error in
|
|
204
|
+
guard let image = image else {
|
|
205
|
+
print("Image capture error: \(String(describing: error))")
|
|
206
|
+
call.reject("Image capture error: \(String(describing: error))")
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
let imageData: Data?
|
|
211
|
+
if (self.cameraPosition == "front") {
|
|
212
|
+
let flippedImage = image.withHorizontallyFlippedOrientation()
|
|
213
|
+
imageData = flippedImage.jpegData(compressionQuality: CGFloat(quality!/100))
|
|
214
|
+
} else {
|
|
215
|
+
imageData = image.jpegData(compressionQuality: CGFloat(quality!/100))
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (self.storeToFile == false){
|
|
219
|
+
let imageBase64 = imageData?.base64EncodedString()
|
|
220
|
+
call.resolve(["value": imageBase64!])
|
|
221
|
+
} else {
|
|
222
|
+
do {
|
|
223
|
+
let fileUrl = self.getTempFilePath()
|
|
224
|
+
try imageData?.write(to:fileUrl)
|
|
225
|
+
call.resolve(["value": fileUrl.absoluteString])
|
|
226
|
+
} catch {
|
|
227
|
+
call.reject("Error writing image to file")
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
181
233
|
|
|
182
234
|
@objc func getSupportedFlashModes(_ call: CAPPluginCall) {
|
|
183
235
|
do {
|
|
@@ -217,5 +269,37 @@ public class CameraPreview: CAPPlugin {
|
|
|
217
269
|
call.reject("failed to set flash mode")
|
|
218
270
|
}
|
|
219
271
|
}
|
|
272
|
+
|
|
273
|
+
@objc func startRecordVideo(_ call: CAPPluginCall) {
|
|
274
|
+
DispatchQueue.main.async {
|
|
275
|
+
|
|
276
|
+
let quality: Int? = call.getInt("quality", 85)
|
|
277
|
+
|
|
278
|
+
self.cameraController.captureVideo { (image, error) in
|
|
279
|
+
|
|
280
|
+
guard let image = image else {
|
|
281
|
+
print(error ?? "Image capture error")
|
|
282
|
+
guard let error = error else {
|
|
283
|
+
call.reject("Image capture error")
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
call.reject(error.localizedDescription)
|
|
287
|
+
return
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
//self.videoUrl = image
|
|
291
|
+
|
|
292
|
+
call.resolve(["value":image.absoluteString])
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
@objc func stopRecordVideo(_ call: CAPPluginCall) {
|
|
299
|
+
|
|
300
|
+
self.cameraController.stopRecording { (error) in
|
|
301
|
+
|
|
302
|
+
}
|
|
303
|
+
}
|
|
220
304
|
|
|
221
305
|
}
|
|
@@ -14,8 +14,6 @@
|
|
|
14
14
|
4C2070D622DA87B100D1AD33 /* CoreImage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070D522DA87B100D1AD33 /* CoreImage.framework */; };
|
|
15
15
|
4C2070D822DA87C600D1AD33 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070D722DA87C500D1AD33 /* QuartzCore.framework */; };
|
|
16
16
|
4C2070DA22DA87CE00D1AD33 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070D922DA87CE00D1AD33 /* CoreVideo.framework */; };
|
|
17
|
-
4C2070DC22DA87D700D1AD33 /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070DB22DA87D700D1AD33 /* GLKit.framework */; };
|
|
18
|
-
4C2070DE22DA87E700D1AD33 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070DD22DA87E700D1AD33 /* OpenGLES.framework */; };
|
|
19
17
|
4C2070E022DA87F500D1AD33 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070DF22DA87F500D1AD33 /* CoreGraphics.framework */; };
|
|
20
18
|
4C2070E222DA87FB00D1AD33 /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070E122DA87FB00D1AD33 /* AssetsLibrary.framework */; };
|
|
21
19
|
4C2070E422DA881600D1AD33 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C2070E322DA881600D1AD33 /* CoreLocation.framework */; };
|
|
@@ -77,8 +75,6 @@
|
|
|
77
75
|
4C2070E422DA881600D1AD33 /* CoreLocation.framework in Frameworks */,
|
|
78
76
|
4C2070E222DA87FB00D1AD33 /* AssetsLibrary.framework in Frameworks */,
|
|
79
77
|
4C2070E022DA87F500D1AD33 /* CoreGraphics.framework in Frameworks */,
|
|
80
|
-
4C2070DE22DA87E700D1AD33 /* OpenGLES.framework in Frameworks */,
|
|
81
|
-
4C2070DC22DA87D700D1AD33 /* GLKit.framework in Frameworks */,
|
|
82
78
|
4C2070D822DA87C600D1AD33 /* QuartzCore.framework in Frameworks */,
|
|
83
79
|
4C2070D622DA87B100D1AD33 /* CoreImage.framework in Frameworks */,
|
|
84
80
|
4C2070D222DA878E00D1AD33 /* ImageIO.framework in Frameworks */,
|
|
@@ -418,7 +414,7 @@
|
|
|
418
414
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
|
419
415
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
|
420
416
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
|
421
|
-
IPHONEOS_DEPLOYMENT_TARGET =
|
|
417
|
+
IPHONEOS_DEPLOYMENT_TARGET = 12.1;
|
|
422
418
|
MTL_ENABLE_DEBUG_INFO = YES;
|
|
423
419
|
ONLY_ACTIVE_ARCH = YES;
|
|
424
420
|
SDKROOT = iphoneos;
|
|
@@ -473,7 +469,7 @@
|
|
|
473
469
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
|
474
470
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
|
475
471
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
|
476
|
-
IPHONEOS_DEPLOYMENT_TARGET =
|
|
472
|
+
IPHONEOS_DEPLOYMENT_TARGET = 12.1;
|
|
477
473
|
MTL_ENABLE_DEBUG_INFO = NO;
|
|
478
474
|
SDKROOT = iphoneos;
|
|
479
475
|
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
package/ios/Podfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
platform :ios, '
|
|
1
|
+
platform :ios, '12.1'
|
|
2
2
|
|
|
3
3
|
target 'Plugin' do
|
|
4
4
|
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
|
|
@@ -10,4 +10,4 @@ target 'PluginTests' do
|
|
|
10
10
|
use_frameworks!
|
|
11
11
|
|
|
12
12
|
pod 'Capacitor', :path => '../node_modules/@capacitor/ios'
|
|
13
|
-
end
|
|
13
|
+
end
|