From 1d99c8b23c01e81123c63eb0af8b614ea6592000 Mon Sep 17 00:00:00 2001 From: Gelinger Media Date: Tue, 8 Nov 2022 02:10:21 +0100 Subject: [PATCH 1/8] first step adding horizontalFOV --- .../camera/preview/CameraPreview.java | 21 +++++++++++++++++++ ios/Plugin/CameraController.swift | 21 ++++++++++++++++++- ios/Plugin/Plugin.m | 1 + ios/Plugin/Plugin.swift | 11 ++++++++++ src/definitions.ts | 3 +++ src/web.ts | 9 ++++++++ 6 files changed, 65 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java b/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java index 83ef9ad7..befa70d8 100644 --- a/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +++ b/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java @@ -172,6 +172,27 @@ public void getSupportedFlashModes(PluginCall call) { call.resolve(jsObject); } + + + + @PluginMethod + public void getHorizontalFov(PluginCall call) { + if (this.hasCamera(call) == false) { + call.reject("Camera is not running"); + return; + } + + Camera camera = fragment.getCamera(); + Camera.Parameters params = camera.getParameters(); + + float horizontalViewAngle = params.getHorizontalViewAngle(); + + + call.resolve(horizontalViewAngle); + } + + + @PluginMethod public void setFlashMode(PluginCall call) { if (this.hasCamera(call) == false) { diff --git a/ios/Plugin/CameraController.swift b/ios/Plugin/CameraController.swift index 009c1d95..7b2adc43 100644 --- a/ios/Plugin/CameraController.swift +++ b/ios/Plugin/CameraController.swift @@ -279,7 +279,7 @@ extension CameraController { self.sampleBufferCaptureCompletionBlock = completion } - func getSupportedFlashModes() throws -> [String] { + func getSupportedFlashModes() throws -> Float { var currentCamera: AVCaptureDevice? switch currentCameraPosition { case .front: @@ -323,7 +323,26 @@ extension CameraController { return supportedFlashModesAsStrings } + func getHorizontalFov() throws -> [String] { + var currentCamera: AVCaptureDevice? + switch currentCameraPosition { + case .front: + currentCamera = self.frontCamera! + case .rear: + currentCamera = self.rearCamera! + default: break + } + guard + let device = currentCamera + else { + throw CameraControllerError.noCamerasAvailable + } + + + return device.activeFormat.videoFieldOfView; + + } func setFlashMode(flashMode: AVCaptureDevice.FlashMode) throws { var currentCamera: AVCaptureDevice? switch currentCameraPosition { diff --git a/ios/Plugin/Plugin.m b/ios/Plugin/Plugin.m index 06fb55e1..b8fb86ce 100644 --- a/ios/Plugin/Plugin.m +++ b/ios/Plugin/Plugin.m @@ -10,6 +10,7 @@ CAP_PLUGIN_METHOD(captureSample, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(flip, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(getSupportedFlashModes, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(getHorizontalFov, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(setFlashMode, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(startRecordVideo, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(stopRecordVideo, CAPPluginReturnPromise); diff --git a/ios/Plugin/Plugin.swift b/ios/Plugin/Plugin.swift index 2fcb754c..2f0e4860 100644 --- a/ios/Plugin/Plugin.swift +++ b/ios/Plugin/Plugin.swift @@ -227,6 +227,17 @@ public class CameraPreview: CAPPlugin { } } + + + @objc func getHorizontalFov(_ call: CAPPluginCall) { + do { + let supportedFlashModes = try self.cameraController.getHorizontalFov() + call.resolve(["result": horizontalFov]) + } catch { + call.reject("failed to get FOV") + } + } + @objc func setFlashMode(_ call: CAPPluginCall) { guard let flashMode = call.getString("flashMode") else { call.reject("failed to set flash mode. required parameter flashMode is missing") diff --git a/src/definitions.ts b/src/definitions.ts index 9aa4a5fe..eaae07f6 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -66,6 +66,9 @@ export interface CameraPreviewPlugin { getSupportedFlashModes(): Promise<{ result: CameraPreviewFlashMode[]; }>; + getHorizontalFov(): Promise<{ + result: string; + }>; setFlashMode(options: { flashMode: CameraPreviewFlashMode | string }): Promise; flip(): Promise; setOpacity(options: CameraOpacityOptions): Promise<{}>; diff --git a/src/web.ts b/src/web.ts index f5138b26..e306cd1d 100644 --- a/src/web.ts +++ b/src/web.ts @@ -155,6 +155,15 @@ export class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin { throw new Error('getSupportedFlashModes not supported under the web platform'); } + + async getHorizontalFov(): Promise<{ + result: string; + }> { + throw new Error('getHorizontalFov not supported under the web platform'); + } + + + async setFlashMode(_options: { flashMode: CameraPreviewFlashMode | string }): Promise { throw new Error('setFlashMode not supported under the web platform'); } From 4b451e38fdf608471312fc44cbdb4974d94ddd39 Mon Sep 17 00:00:00 2001 From: Gelinger Media Date: Tue, 8 Nov 2022 02:32:39 +0100 Subject: [PATCH 2/8] better android version --- .../com/ahm/capacitor/camera/preview/CameraPreview.java | 7 ++++--- src/definitions.ts | 2 +- src/web.ts | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java b/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java index befa70d8..5943bd5c 100644 --- a/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +++ b/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java @@ -186,9 +186,10 @@ public void getHorizontalFov(PluginCall call) { Camera.Parameters params = camera.getParameters(); float horizontalViewAngle = params.getHorizontalViewAngle(); - - - call.resolve(horizontalViewAngle); + + JSObject jsObject = new JSObject(); + jsObject.put("result", horizontalViewAngle); + call.resolve(jsObject); } diff --git a/src/definitions.ts b/src/definitions.ts index eaae07f6..eede6294 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -67,7 +67,7 @@ export interface CameraPreviewPlugin { result: CameraPreviewFlashMode[]; }>; getHorizontalFov(): Promise<{ - result: string; + result: number; }>; setFlashMode(options: { flashMode: CameraPreviewFlashMode | string }): Promise; flip(): Promise; diff --git a/src/web.ts b/src/web.ts index e306cd1d..3e884527 100644 --- a/src/web.ts +++ b/src/web.ts @@ -157,7 +157,7 @@ export class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin { async getHorizontalFov(): Promise<{ - result: string; + result: number; }> { throw new Error('getHorizontalFov not supported under the web platform'); } From 8a54d287c29b9b2ef169e362c798d1b8bebd3c0d Mon Sep 17 00:00:00 2001 From: Gelinger Media Date: Wed, 9 Nov 2022 20:08:31 +0100 Subject: [PATCH 3/8] anothe small fix --- src/definitions.ts | 2 +- src/web.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/definitions.ts b/src/definitions.ts index eede6294..70e9b9a5 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -67,7 +67,7 @@ export interface CameraPreviewPlugin { result: CameraPreviewFlashMode[]; }>; getHorizontalFov(): Promise<{ - result: number; + result: any; }>; setFlashMode(options: { flashMode: CameraPreviewFlashMode | string }): Promise; flip(): Promise; diff --git a/src/web.ts b/src/web.ts index 3e884527..4e8c3026 100644 --- a/src/web.ts +++ b/src/web.ts @@ -157,7 +157,7 @@ export class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin { async getHorizontalFov(): Promise<{ - result: number; + result: any; }> { throw new Error('getHorizontalFov not supported under the web platform'); } From c90332581261877407b139f9016c41d8c608a7ac Mon Sep 17 00:00:00 2001 From: Gelinger Media Date: Wed, 9 Nov 2022 22:25:17 +0100 Subject: [PATCH 4/8] Better readme for FOV --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index debaf657..4b835940 100644 --- a/README.md +++ b/README.md @@ -247,6 +247,24 @@ import { CameraPreviewFlashMode } from '@capacitor-community/camera-preview'; const flashModes = await CameraPreview.getSupportedFlashModes(); const supportedFlashModes: CameraPreviewFlashMode[] = flashModes.result; ``` + + + +### getHorizontalFov() + +Get the horizontal FOV of camera the camera device currently started. Returns a float
+ +Please note that camera should be already started to get this value. + +```javascript + + +const cameraFovRequest = await CameraPreview.getHorizontalFov(); +const cameraFovRequest = cameraFovRequest.result; +``` + + + ### setFlashMode(options) Set the flash mode. See [FLASH_MODE](#camera_Settings.FlashMode) for details about the possible values for flashMode.
From d4c774b0173fd4c6988584c46e6d5fa8c2952597 Mon Sep 17 00:00:00 2001 From: Gelinger Media Date: Fri, 11 Nov 2022 09:54:20 +0100 Subject: [PATCH 5/8] Fix for iOS --- ios/Plugin/CameraController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Plugin/CameraController.swift b/ios/Plugin/CameraController.swift index 7b2adc43..e0788eb0 100644 --- a/ios/Plugin/CameraController.swift +++ b/ios/Plugin/CameraController.swift @@ -279,7 +279,7 @@ extension CameraController { self.sampleBufferCaptureCompletionBlock = completion } - func getSupportedFlashModes() throws -> Float { + func getSupportedFlashModes() throws -> [String] { var currentCamera: AVCaptureDevice? switch currentCameraPosition { case .front: @@ -323,7 +323,7 @@ extension CameraController { return supportedFlashModesAsStrings } - func getHorizontalFov() throws -> [String] { + func getHorizontalFov() throws -> String { var currentCamera: AVCaptureDevice? switch currentCameraPosition { case .front: From 785ce354e3e34a51565f090f87e9b01f34818221 Mon Sep 17 00:00:00 2001 From: Gelinger Media Date: Sun, 11 Jun 2023 21:11:05 +0200 Subject: [PATCH 6/8] fix ios --- ios/Plugin/CameraController.swift | 4 ++-- ios/Plugin/Plugin.swift | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ios/Plugin/CameraController.swift b/ios/Plugin/CameraController.swift index e0788eb0..442774a0 100644 --- a/ios/Plugin/CameraController.swift +++ b/ios/Plugin/CameraController.swift @@ -339,8 +339,8 @@ extension CameraController { throw CameraControllerError.noCamerasAvailable } - - return device.activeFormat.videoFieldOfView; + let horizontalFov = String(device.activeFormat.videoFieldOfView) + return horizontalFov } func setFlashMode(flashMode: AVCaptureDevice.FlashMode) throws { diff --git a/ios/Plugin/Plugin.swift b/ios/Plugin/Plugin.swift index 2f0e4860..42e19241 100644 --- a/ios/Plugin/Plugin.swift +++ b/ios/Plugin/Plugin.swift @@ -229,9 +229,10 @@ public class CameraPreview: CAPPlugin { + @objc func getHorizontalFov(_ call: CAPPluginCall) { do { - let supportedFlashModes = try self.cameraController.getHorizontalFov() + let horizontalFov = try self.cameraController.getHorizontalFov() call.resolve(["result": horizontalFov]) } catch { call.reject("failed to get FOV") From 022c1e2d24db99a884cf4f5c0559f6400bcfd881 Mon Sep 17 00:00:00 2001 From: Gelinger Media Date: Fri, 16 Jun 2023 13:26:45 +0200 Subject: [PATCH 7/8] Update package.json 4.8.0 --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index ddb88f59..9b0b17bb 100644 --- a/package.json +++ b/package.json @@ -25,9 +25,9 @@ "author": "Ariel Hernandez Musa", "license": "MIT", "devDependencies": { - "@capacitor/android": "^5.0.0", - "@capacitor/core": "^5.0.0", - "@capacitor/ios": "^5.0.0", + "@capacitor/android": "^4.8.0", + "@capacitor/core": "^4.8.0", + "@capacitor/ios": "^4.8.0", "@ionic/eslint-config": "^0.3.0", "@ionic/prettier-config": "^2.0.0", "@ionic/swiftlint-config": "^1.1.2", From 7a1f3ba90ca7c8d3f2346922c2654690fbdc3805 Mon Sep 17 00:00:00 2001 From: Gelinger Media Date: Fri, 16 Jun 2023 13:28:16 +0200 Subject: [PATCH 8/8] Update package.json --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9b0b17bb..ddb88f59 100644 --- a/package.json +++ b/package.json @@ -25,9 +25,9 @@ "author": "Ariel Hernandez Musa", "license": "MIT", "devDependencies": { - "@capacitor/android": "^4.8.0", - "@capacitor/core": "^4.8.0", - "@capacitor/ios": "^4.8.0", + "@capacitor/android": "^5.0.0", + "@capacitor/core": "^5.0.0", + "@capacitor/ios": "^5.0.0", "@ionic/eslint-config": "^0.3.0", "@ionic/prettier-config": "^2.0.0", "@ionic/swiftlint-config": "^1.1.2",