capacitor-camera-view 2.2.0 → 2.3.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 CHANGED
@@ -29,6 +29,7 @@
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.
32
33
  - 🔍 **Barcode detection** support.
33
34
  - 📱 **Virtual device support** for automatic lens selection based on zoom level and focus (iOS only).
34
35
  - 🔦 Control **zoom**, **flash** and **torch** modes programmatically.
@@ -62,12 +63,70 @@ Add the following keys to your app's `Info.plist` file:
62
63
  <string>To capture photos and videos</string>
63
64
  ```
64
65
 
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
+
65
76
  #### Android
66
77
 
67
- The `CAMERA` permission is automatically added by Capacitor. Ensure your `AndroidManifest.xml` includes it if needed for specific configurations:
78
+ The `CAMERA` permission is added to your app's `AndroidManifest.xml` automatically by the plugin. If you plan to use `startRecording` with `enableAudio: true`, the `RECORD_AUDIO` permission is also declared automatically by the plugin. You can verify these in your merged manifest:
68
79
 
69
80
  ```xml
70
81
  <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'
71
130
  ```
72
131
 
73
132
  ## ▶️ Basic Usage
@@ -174,6 +233,54 @@ CameraView.addListener('barcodeDetected', (data) => {
174
233
 
175
234
  See the [`BarcodeDetectionData`](#barcodedetectiondata) interface for details on the event payload.
176
235
 
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
+
177
284
  ## 🧪 Example App
178
285
 
179
286
  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.
@@ -206,6 +313,8 @@ chore: update dependencies
206
313
  * [`isRunning()`](#isrunning)
207
314
  * [`capture(...)`](#capture)
208
315
  * [`captureSample(...)`](#capturesample)
316
+ * [`startRecording(...)`](#startrecording)
317
+ * [`stopRecording()`](#stoprecording)
209
318
  * [`flipCamera()`](#flipcamera)
210
319
  * [`getAvailableDevices()`](#getavailabledevices)
211
320
  * [`getZoom()`](#getzoom)
@@ -217,7 +326,7 @@ chore: update dependencies
217
326
  * [`getTorchMode()`](#gettorchmode)
218
327
  * [`setTorchMode(...)`](#settorchmode)
219
328
  * [`checkPermissions()`](#checkpermissions)
220
- * [`requestPermissions()`](#requestpermissions)
329
+ * [`requestPermissions(...)`](#requestpermissions)
221
330
  * [`addListener('barcodeDetected', ...)`](#addlistenerbarcodedetected-)
222
331
  * [`removeAllListeners(...)`](#removealllisteners)
223
332
  * [Interfaces](#interfaces)
@@ -321,6 +430,40 @@ not yet well supported on the web.
321
430
  --------------------
322
431
 
323
432
 
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.3.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&lt;<a href="#videorecordingresponse">VideoRecordingResponse</a>&gt;</code>
461
+
462
+ **Since:** 2.3.0
463
+
464
+ --------------------
465
+
466
+
324
467
  ### flipCamera()
325
468
 
326
469
  ```typescript
@@ -481,7 +624,7 @@ Set the torch (flashlight) mode and intensity.
481
624
  checkPermissions() => Promise<PermissionStatus>
482
625
  ```
483
626
 
484
- Check camera permission status without requesting permissions.
627
+ Check camera and microphone permission status without requesting permissions.
485
628
 
486
629
  **Returns:** <code>Promise&lt;<a href="#permissionstatus">PermissionStatus</a>&gt;</code>
487
630
 
@@ -490,13 +633,20 @@ Check camera permission status without requesting permissions.
490
633
  --------------------
491
634
 
492
635
 
493
- ### requestPermissions()
636
+ ### requestPermissions(...)
494
637
 
495
638
  ```typescript
496
- requestPermissions() => Promise<PermissionStatus>
639
+ requestPermissions(options?: { permissions?: CameraPermissionType[] | undefined; } | undefined) => Promise<PermissionStatus>
497
640
  ```
498
641
 
499
- Request camera permission from the user.
642
+ Request camera and/or microphone permissions from the user.
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 |
500
650
 
501
651
  **Returns:** <code>Promise&lt;<a href="#permissionstatus">PermissionStatus</a>&gt;</code>
502
652
 
@@ -581,6 +731,25 @@ Configuration options for capturing photos and samples.
581
731
  | **`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 |
582
732
 
583
733
 
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.3.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.3.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.3.0 |
751
+
752
+
584
753
  #### GetAvailableDevicesResponse
585
754
 
586
755
  Response for getting available camera devices.
@@ -652,11 +821,12 @@ Response for getting the current torch mode.
652
821
 
653
822
  #### PermissionStatus
654
823
 
655
- Response for the camera permission status.
824
+ Response for the camera and microphone permission status.
656
825
 
657
- | Prop | Type | Description |
658
- | ------------ | ----------------------------------------------------------- | ---------------------------------- |
659
- | **`camera`** | <code><a href="#permissionstate">PermissionState</a></code> | The state of the camera permission |
826
+ | Prop | Type | Description |
827
+ | ---------------- | ----------------------------------------------------------- | -------------------------------------- |
828
+ | **`camera`** | <code><a href="#permissionstate">PermissionState</a></code> | The state of the camera permission |
829
+ | **`microphone`** | <code><a href="#permissionstate">PermissionState</a></code> | The state of the microphone permission |
660
830
 
661
831
 
662
832
  #### PluginListenerHandle
@@ -730,6 +900,13 @@ depending on the `saveToFile` option in the <a href="#captureoptions">CaptureOpt
730
900
  <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>
731
901
 
732
902
 
903
+ #### VideoRecordingQuality
904
+
905
+ Video recording quality presets.
906
+
907
+ <code>'lowest' | 'sd' | 'hd' | 'fhd' | 'uhd' | 'highest'</code>
908
+
909
+
733
910
  #### FlashMode
734
911
 
735
912
  Flash mode options for the camera.
@@ -744,4 +921,13 @@ Flash mode options for the camera.
744
921
 
745
922
  <code>'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'</code>
746
923
 
924
+
925
+ #### CameraPermissionType
926
+
927
+ Permission types that can be requested.
928
+ - 'camera': Camera access permission
929
+ - 'microphone': Microphone access permission (needed for video recording with audio)
930
+
931
+ <code>'camera' | 'microphone'</code>
932
+
747
933
  </docgen-api>
@@ -78,6 +78,7 @@ 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}"
81
82
 
82
83
  // ML Kit for barcode scanning
83
84
  implementation "com.google.mlkit:barcode-scanning:17.3.0"
@@ -1,2 +1,3 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
2
3
  </manifest>