capacitor-camera-view 2.2.0-rc.1 → 2.2.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/README.md +17 -202
- package/android/build.gradle +0 -1
- package/android/src/main/AndroidManifest.xml +0 -1
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/CameraView.kt +4 -287
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/CameraViewPlugin.kt +8 -112
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/model/BarcodeDetectionResult.kt +1 -0
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/utils.kt +1 -21
- package/dist/docs.json +21 -201
- package/dist/esm/definitions.d.ts +23 -85
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +4 -20
- package/dist/esm/web.js +16 -151
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +16 -151
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +16 -151
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CameraViewPlugin/CameraError.swift +0 -28
- package/ios/Sources/CameraViewPlugin/CameraEvents.swift +27 -3
- package/ios/Sources/CameraViewPlugin/CameraSessionConfiguration.swift +8 -8
- package/ios/Sources/CameraViewPlugin/CameraViewManager+BarcodeScan.swift +34 -3
- package/ios/Sources/CameraViewPlugin/CameraViewManager+PhotoCapture.swift +14 -13
- package/ios/Sources/CameraViewPlugin/CameraViewManager.swift +150 -159
- package/ios/Sources/CameraViewPlugin/CameraViewPlugin.swift +15 -114
- package/ios/Sources/CameraViewPlugin/TempFileManager.swift +34 -68
- package/package.json +12 -12
- package/android/src/main/java/com/michaelwolz/capacitorcameraview/model/VideoRecordingQuality.kt +0 -10
- package/ios/Sources/CameraViewPlugin/CameraViewManager+VideoRecording.swift +0 -302
package/README.md
CHANGED
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
|
|
30
30
|
- 📹 Embed a **live camera feed** directly into your app.
|
|
31
31
|
- 📸 Capture photos or frames from the camera preview.
|
|
32
|
-
- 🎥 **Video recording** with optional audio support.
|
|
33
32
|
- 🔍 **Barcode detection** support.
|
|
34
33
|
- 📱 **Virtual device support** for automatic lens selection based on zoom level and focus (iOS only).
|
|
35
34
|
- 🔦 Control **zoom**, **flash** and **torch** modes programmatically.
|
|
@@ -63,70 +62,12 @@ Add the following keys to your app's `Info.plist` file:
|
|
|
63
62
|
<string>To capture photos and videos</string>
|
|
64
63
|
```
|
|
65
64
|
|
|
66
|
-
If you plan to use `startRecording` with `enableAudio: true`, also add:
|
|
67
|
-
|
|
68
|
-
```xml
|
|
69
|
-
<key>NSMicrophoneUsageDescription</key>
|
|
70
|
-
<string>To record audio with video</string>
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
> [!IMPORTANT]
|
|
74
|
-
> The `NSMicrophoneUsageDescription` key must be present in `Info.plist` **before** microphone permission is ever requested — even if the request happens automatically when starting a recording with audio. Omitting it will cause your app to crash at runtime.
|
|
75
|
-
|
|
76
65
|
#### Android
|
|
77
66
|
|
|
78
|
-
The `CAMERA` permission is added
|
|
67
|
+
The `CAMERA` permission is automatically added by Capacitor. Ensure your `AndroidManifest.xml` includes it if needed for specific configurations:
|
|
79
68
|
|
|
80
69
|
```xml
|
|
81
70
|
<uses-permission android:name="android.permission.CAMERA" />
|
|
82
|
-
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
> [!IMPORTANT]
|
|
86
|
-
> Declaring a permission in `AndroidManifest.xml` is required for the system to allow requesting it at runtime. The plugin handles this for you, but make sure you are not accidentally stripping the permission in your build configuration.
|
|
87
|
-
|
|
88
|
-
## 🔒 Permissions
|
|
89
|
-
|
|
90
|
-
The plugin handles permissions for you automatically when a feature that requires them is used. However, you can also request permissions explicitly in advance.
|
|
91
|
-
|
|
92
|
-
### Requesting permissions explicitly
|
|
93
|
-
|
|
94
|
-
By default, `requestPermissions()` only requests **camera** permission, preserving backward compatibility:
|
|
95
|
-
|
|
96
|
-
```typescript
|
|
97
|
-
// Request camera permission only (default behavior)
|
|
98
|
-
const status = await CameraView.requestPermissions();
|
|
99
|
-
console.log(status.camera); // 'granted' | 'denied' | 'prompt'
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
To also request **microphone** permission (needed for video recording with audio), pass the `permissions` option:
|
|
103
|
-
|
|
104
|
-
```typescript
|
|
105
|
-
// Request both camera and microphone permissions
|
|
106
|
-
const status = await CameraView.requestPermissions({
|
|
107
|
-
permissions: ['camera', 'microphone'],
|
|
108
|
-
});
|
|
109
|
-
console.log(status.camera); // 'granted' | 'denied' | 'prompt'
|
|
110
|
-
console.log(status.microphone); // 'granted' | 'denied' | 'prompt'
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### Automatic permission requests
|
|
114
|
-
|
|
115
|
-
You do not need to call `requestPermissions()` manually. The plugin will automatically request the required permissions when a feature is first used:
|
|
116
|
-
|
|
117
|
-
- **Camera** permission is requested automatically when `start()` is called.
|
|
118
|
-
- **Microphone** permission is requested automatically when `startRecording({ enableAudio: true })` is called.
|
|
119
|
-
|
|
120
|
-
Regardless of whether you request permissions manually or rely on the automatic flow, the corresponding entries **must** be declared in your app's platform configuration (`Info.plist` on iOS, `AndroidManifest.xml` on Android) as described above.
|
|
121
|
-
|
|
122
|
-
### Checking permission status
|
|
123
|
-
|
|
124
|
-
Use `checkPermissions()` to query the current permission state without triggering a system prompt:
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
const status = await CameraView.checkPermissions();
|
|
128
|
-
console.log(status.camera); // 'granted' | 'denied' | 'prompt'
|
|
129
|
-
console.log(status.microphone); // 'granted' | 'denied' | 'prompt'
|
|
130
71
|
```
|
|
131
72
|
|
|
132
73
|
## ▶️ Basic Usage
|
|
@@ -233,54 +174,6 @@ CameraView.addListener('barcodeDetected', (data) => {
|
|
|
233
174
|
|
|
234
175
|
See the [`BarcodeDetectionData`](#barcodedetectiondata) interface for details on the event payload.
|
|
235
176
|
|
|
236
|
-
## 🎥 Video Recording
|
|
237
|
-
|
|
238
|
-
This plugin supports recording video directly from the live camera feed.
|
|
239
|
-
|
|
240
|
-
**How it works:**
|
|
241
|
-
* **iOS:** Uses `AVCaptureMovieFileOutput` on top of the existing `AVCaptureSession`. Output is saved as `.mp4`.
|
|
242
|
-
* **Android:** Uses the CameraX `VideoCapture` use case via `LifecycleCameraController`. Output is saved as `.mp4`.
|
|
243
|
-
* **Web:** Uses the browser `MediaRecorder` API on the existing `MediaStream`. Output is a `.webm` blob URL (MP4 is not broadly supported by browsers).
|
|
244
|
-
|
|
245
|
-
**Basic usage:**
|
|
246
|
-
|
|
247
|
-
```typescript
|
|
248
|
-
import { CameraView } from 'capacitor-camera-view';
|
|
249
|
-
|
|
250
|
-
// Start recording (camera must already be running)
|
|
251
|
-
await CameraView.startRecording({ enableAudio: false });
|
|
252
|
-
|
|
253
|
-
// Stop recording and get the result
|
|
254
|
-
const result = await CameraView.stopRecording();
|
|
255
|
-
console.log('Video saved to:', result.webPath);
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
**Playing back the recorded video:**
|
|
259
|
-
|
|
260
|
-
```html
|
|
261
|
-
<video [src]="videoPath" controls></video>
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
**Recording with audio:**
|
|
265
|
-
|
|
266
|
-
```typescript
|
|
267
|
-
await CameraView.startRecording({ enableAudio: true });
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
**Recording with explicit quality preset (native):**
|
|
271
|
-
|
|
272
|
-
```typescript
|
|
273
|
-
await CameraView.startRecording({
|
|
274
|
-
enableAudio: true,
|
|
275
|
-
videoQuality: 'fhd', // lowest | sd | hd | fhd | uhd | highest
|
|
276
|
-
});
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
> [!NOTE]
|
|
280
|
-
> When `enableAudio: true` is used, the plugin automatically requests microphone permission from the user if it has not been granted yet. The permission declaration must still be present in your platform configuration — see the [Permissions](#-permissions) section for details.
|
|
281
|
-
|
|
282
|
-
See the [`VideoRecordingOptions`](#videorecordingoptions) and [`VideoRecordingResponse`](#videorecordingresponse) interfaces in the API section for the full set of options.
|
|
283
|
-
|
|
284
177
|
## 🧪 Example App
|
|
285
178
|
|
|
286
179
|
To see the plugin in action, check out the example app in the `example-app` folder. The app demonstrates how to integrate and use the Capacitor Camera View plugin in an Ionic Angular project.
|
|
@@ -313,8 +206,6 @@ chore: update dependencies
|
|
|
313
206
|
* [`isRunning()`](#isrunning)
|
|
314
207
|
* [`capture(...)`](#capture)
|
|
315
208
|
* [`captureSample(...)`](#capturesample)
|
|
316
|
-
* [`startRecording(...)`](#startrecording)
|
|
317
|
-
* [`stopRecording()`](#stoprecording)
|
|
318
209
|
* [`flipCamera()`](#flipcamera)
|
|
319
210
|
* [`getAvailableDevices()`](#getavailabledevices)
|
|
320
211
|
* [`getZoom()`](#getzoom)
|
|
@@ -326,7 +217,7 @@ chore: update dependencies
|
|
|
326
217
|
* [`getTorchMode()`](#gettorchmode)
|
|
327
218
|
* [`setTorchMode(...)`](#settorchmode)
|
|
328
219
|
* [`checkPermissions()`](#checkpermissions)
|
|
329
|
-
* [`requestPermissions(
|
|
220
|
+
* [`requestPermissions()`](#requestpermissions)
|
|
330
221
|
* [`addListener('barcodeDetected', ...)`](#addlistenerbarcodedetected-)
|
|
331
222
|
* [`removeAllListeners(...)`](#removealllisteners)
|
|
332
223
|
* [Interfaces](#interfaces)
|
|
@@ -430,40 +321,6 @@ not yet well supported on the web.
|
|
|
430
321
|
--------------------
|
|
431
322
|
|
|
432
323
|
|
|
433
|
-
### startRecording(...)
|
|
434
|
-
|
|
435
|
-
```typescript
|
|
436
|
-
startRecording(options?: VideoRecordingOptions | undefined) => Promise<void>
|
|
437
|
-
```
|
|
438
|
-
|
|
439
|
-
Start recording video from the current camera.
|
|
440
|
-
Camera must be running. Throws if already recording.
|
|
441
|
-
|
|
442
|
-
| Param | Type | Description |
|
|
443
|
-
| ------------- | ----------------------------------------------------------------------- | ---------------------------------- |
|
|
444
|
-
| **`options`** | <code><a href="#videorecordingoptions">VideoRecordingOptions</a></code> | - Optional recording configuration |
|
|
445
|
-
|
|
446
|
-
**Since:** 2.2.0
|
|
447
|
-
|
|
448
|
-
--------------------
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
### stopRecording()
|
|
452
|
-
|
|
453
|
-
```typescript
|
|
454
|
-
stopRecording() => Promise<VideoRecordingResponse>
|
|
455
|
-
```
|
|
456
|
-
|
|
457
|
-
Stop the current video recording and return the result.
|
|
458
|
-
Throws if no recording is in progress.
|
|
459
|
-
|
|
460
|
-
**Returns:** <code>Promise<<a href="#videorecordingresponse">VideoRecordingResponse</a>></code>
|
|
461
|
-
|
|
462
|
-
**Since:** 2.2.0
|
|
463
|
-
|
|
464
|
-
--------------------
|
|
465
|
-
|
|
466
|
-
|
|
467
324
|
### flipCamera()
|
|
468
325
|
|
|
469
326
|
```typescript
|
|
@@ -624,7 +481,7 @@ Set the torch (flashlight) mode and intensity.
|
|
|
624
481
|
checkPermissions() => Promise<PermissionStatus>
|
|
625
482
|
```
|
|
626
483
|
|
|
627
|
-
Check camera
|
|
484
|
+
Check camera permission status without requesting permissions.
|
|
628
485
|
|
|
629
486
|
**Returns:** <code>Promise<<a href="#permissionstatus">PermissionStatus</a>></code>
|
|
630
487
|
|
|
@@ -633,20 +490,13 @@ Check camera and microphone permission status without requesting permissions.
|
|
|
633
490
|
--------------------
|
|
634
491
|
|
|
635
492
|
|
|
636
|
-
### requestPermissions(
|
|
493
|
+
### requestPermissions()
|
|
637
494
|
|
|
638
495
|
```typescript
|
|
639
|
-
requestPermissions(
|
|
496
|
+
requestPermissions() => Promise<PermissionStatus>
|
|
640
497
|
```
|
|
641
498
|
|
|
642
|
-
Request camera
|
|
643
|
-
|
|
644
|
-
By default, only camera permission is requested. To also request microphone
|
|
645
|
-
permission (needed for video recording with audio), pass `{ permissions: ['camera', 'microphone'] }`.
|
|
646
|
-
|
|
647
|
-
| Param | Type | Description |
|
|
648
|
-
| ------------- | ------------------------------------------------------ | --------------------------------------------------------- |
|
|
649
|
-
| **`options`** | <code>{ permissions?: CameraPermissionType[]; }</code> | - Optional object specifying which permissions to request |
|
|
499
|
+
Request camera permission from the user.
|
|
650
500
|
|
|
651
501
|
**Returns:** <code>Promise<<a href="#permissionstatus">PermissionStatus</a>></code>
|
|
652
502
|
|
|
@@ -731,25 +581,6 @@ Configuration options for capturing photos and samples.
|
|
|
731
581
|
| **`saveToFile`** | <code>boolean</code> | If true, saves to a temporary file and returns the web path instead of base64. The web path can be used to set the src attribute of an image for efficient loading and rendering. This reduces the data that needs to be transferred over the bridge, which can improve performance especially for high-resolution images. | <code>false</code> | 1.1.0 |
|
|
732
582
|
|
|
733
583
|
|
|
734
|
-
#### VideoRecordingOptions
|
|
735
|
-
|
|
736
|
-
Configuration options for video recording.
|
|
737
|
-
|
|
738
|
-
| Prop | Type | Description | Default | Since |
|
|
739
|
-
| ------------------ | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ---------------------- | ----- |
|
|
740
|
-
| **`enableAudio`** | <code>boolean</code> | Whether to record audio with the video. Requires microphone permission. | <code>false</code> | 2.2.0 |
|
|
741
|
-
| **`videoQuality`** | <code><a href="#videorecordingquality">VideoRecordingQuality</a></code> | Video recording quality preset. Native platforms only (iOS/Android). Ignored on web. | <code>'highest'</code> | 2.2.0 |
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
#### VideoRecordingResponse
|
|
745
|
-
|
|
746
|
-
Response from stopping a video recording.
|
|
747
|
-
|
|
748
|
-
| Prop | Type | Description | Since |
|
|
749
|
-
| ------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
750
|
-
| **`webPath`** | <code>string</code> | Web-accessible path to the recorded video file. On web, this is a blob URL. On iOS/Android, this is a path accessible via Capacitor's filesystem. | 2.2.0 |
|
|
751
|
-
|
|
752
|
-
|
|
753
584
|
#### GetAvailableDevicesResponse
|
|
754
585
|
|
|
755
586
|
Response for getting available camera devices.
|
|
@@ -821,12 +652,11 @@ Response for getting the current torch mode.
|
|
|
821
652
|
|
|
822
653
|
#### PermissionStatus
|
|
823
654
|
|
|
824
|
-
Response for the camera
|
|
655
|
+
Response for the camera permission status.
|
|
825
656
|
|
|
826
|
-
| Prop
|
|
827
|
-
|
|
|
828
|
-
| **`camera`**
|
|
829
|
-
| **`microphone`** | <code><a href="#permissionstate">PermissionState</a></code> | The state of the microphone permission |
|
|
657
|
+
| Prop | Type | Description |
|
|
658
|
+
| ------------ | ----------------------------------------------------------- | ---------------------------------- |
|
|
659
|
+
| **`camera`** | <code><a href="#permissionstate">PermissionState</a></code> | The state of the camera permission |
|
|
830
660
|
|
|
831
661
|
|
|
832
662
|
#### PluginListenerHandle
|
|
@@ -840,12 +670,13 @@ Response for the camera and microphone permission status.
|
|
|
840
670
|
|
|
841
671
|
Data for a detected barcode.
|
|
842
672
|
|
|
843
|
-
| Prop | Type | Description
|
|
844
|
-
| ------------------ | ----------------------------------------------------- |
|
|
845
|
-
| **`value`** | <code>string</code> | The decoded string value of the barcode
|
|
846
|
-
| **`
|
|
847
|
-
| **`
|
|
848
|
-
| **`
|
|
673
|
+
| Prop | Type | Description | Since |
|
|
674
|
+
| ------------------ | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
675
|
+
| **`value`** | <code>string</code> | The decoded string value of the barcode | |
|
|
676
|
+
| **`rawBytes`** | <code>number[]</code> | Raw bytes as they were encoded in the barcode. On Android, this is forwarded from ML Kit. On iOS, this is available for descriptor-backed formats such as QR, Aztec, PDF417, and Data Matrix. On web, this is not available because the Barcode Detection API only exposes the decoded string value. | 2.2.0 |
|
|
677
|
+
| **`displayValue`** | <code>string</code> | The display value of the barcode on Android. This is forwarded from ML Kit and may contain a formatted, human-readable representation that differs from the raw decoded value. iOS and web do not expose a separate display value, so this property is only emitted on Android. | |
|
|
678
|
+
| **`type`** | <code>string</code> | The type/format of the barcode (e.g., 'qr', 'code128', etc.) | |
|
|
679
|
+
| **`boundingRect`** | <code><a href="#boundingrect">BoundingRect</a></code> | The bounding rectangle of the barcode in the camera frame. | |
|
|
849
680
|
|
|
850
681
|
|
|
851
682
|
#### BoundingRect
|
|
@@ -899,13 +730,6 @@ depending on the `saveToFile` option in the <a href="#captureoptions">CaptureOpt
|
|
|
899
730
|
<code>T['saveToFile'] extends true ? { /** The web path to the captured photo that can be used to set the src attribute of an image for efficient loading and rendering (when saveToFile is true) */ webPath: string; } : { /** The base64 encoded string of the captured photo (when saveToFile is false or undefined) */ photo: string; }</code>
|
|
900
731
|
|
|
901
732
|
|
|
902
|
-
#### VideoRecordingQuality
|
|
903
|
-
|
|
904
|
-
Video recording quality presets.
|
|
905
|
-
|
|
906
|
-
<code>'lowest' | 'sd' | 'hd' | 'fhd' | 'uhd' | 'highest'</code>
|
|
907
|
-
|
|
908
|
-
|
|
909
733
|
#### FlashMode
|
|
910
734
|
|
|
911
735
|
Flash mode options for the camera.
|
|
@@ -920,13 +744,4 @@ Flash mode options for the camera.
|
|
|
920
744
|
|
|
921
745
|
<code>'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'</code>
|
|
922
746
|
|
|
923
|
-
|
|
924
|
-
#### CameraPermissionType
|
|
925
|
-
|
|
926
|
-
Permission types that can be requested.
|
|
927
|
-
- 'camera': Camera access permission
|
|
928
|
-
- 'microphone': Microphone access permission (needed for video recording with audio)
|
|
929
|
-
|
|
930
|
-
<code>'camera' | 'microphone'</code>
|
|
931
|
-
|
|
932
747
|
</docgen-api>
|
package/android/build.gradle
CHANGED
|
@@ -78,7 +78,6 @@ dependencies {
|
|
|
78
78
|
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
|
|
79
79
|
implementation "androidx.camera:camera-view:${camerax_version}"
|
|
80
80
|
implementation "androidx.camera:camera-mlkit-vision:${camerax_version}"
|
|
81
|
-
implementation "androidx.camera:camera-video:${camerax_version}"
|
|
82
81
|
|
|
83
82
|
// ML Kit for barcode scanning
|
|
84
83
|
implementation "com.google.mlkit:barcode-scanning:17.3.0"
|