feat: Separate usecases (decouple microphone, video, photo) (#168)
* Add props * add props (iOS) * Add use-cases conditionally * Update CameraView+RecordVideo.swift * Update RecordingSession.swift * reconfigure on change * Throw correct errors * Check for audio permission * Move `#if` outward * Throw appropriate errors * Update CameraView+RecordVideo.swift * fix Splashscreen * Dynamic filePath * Fix video extension * add `avci` and `m4v` file types * Fix RecordVideo errors * Fix audio setup * Enable `photo`, `video` and `audio` * Check for `video={true}` in frameProcessor * format * Remove unused DispatchQueue * Update docs * Add `supportsPhotoAndVideoCapture` * Fix view manager * Fix error not being propagated * Catch normal errors too * Update DEVICES.mdx * Update CAPTURING.mdx * Update classdocs
This commit is contained in:
@@ -40,7 +40,13 @@ The most important actions are:
|
||||
|
||||
## Taking Photos
|
||||
|
||||
To take a photo, simply use the Camera's [`takePhoto(...)`](../api/classes/camera.camera-1#takephoto) function:
|
||||
To take a photo you first have to enable photo capture:
|
||||
|
||||
```tsx
|
||||
<Camera {...props} photo={true} />
|
||||
```
|
||||
|
||||
Then, simply use the Camera's [`takePhoto(...)`](../api/classes/camera.camera-1#takephoto) function:
|
||||
|
||||
```ts
|
||||
const photo = await camera.current.takePhoto({
|
||||
@@ -71,9 +77,23 @@ const snapshot = await camera.current.takeSnapshot({
|
||||
While taking snapshots is faster than taking photos, the resulting image has way lower quality. You can combine both functions to create a snapshot to present to the user at first, then deliver the actual high-res photo afterwards.
|
||||
:::
|
||||
|
||||
:::note
|
||||
The `takeSnapshot` function also works with `photo={false}`. For this reason, devices that do not support photo and video capture at the same time can use `video={true}` and fall back to snapshot capture for photos.
|
||||
:::
|
||||
|
||||
## Recording Videos
|
||||
|
||||
To start a video recording, use the Camera's [`startRecording(...)`](../api/classes/camera.camera-1#startrecording) function:
|
||||
To start a video recording you first have to enable video capture:
|
||||
|
||||
```tsx
|
||||
<Camera
|
||||
{...props}
|
||||
video={true}
|
||||
audio={true} // <-- optional
|
||||
/>
|
||||
```
|
||||
|
||||
Then, simply use the Camera's [`startRecording(...)`](../api/classes/camera.camera-1#startrecording) function:
|
||||
|
||||
```ts
|
||||
camera.current.startRecording({
|
||||
@@ -85,10 +105,6 @@ camera.current.startRecording({
|
||||
|
||||
For any error that occured _while recording the video_, the `onRecordingError` callback will be invoked with a [`CaptureError`](../api/classes/cameraerror.cameracaptureerror) and the recording is therefore cancelled.
|
||||
|
||||
:::note
|
||||
Due to limitations of the React Native Bridge, this function can not be awaited. This means, any errors thrown while trying to start the recording (e.g. `capture/recording-in-progress`) can only be caught synchronously (`isBlockingSynchronousMethod`). This will change with the upcoming React Native Re-Architecture.
|
||||
:::
|
||||
|
||||
To stop the video recording, you can call [`stopRecording(...)`](../api/classes/camera.camera-1#stoprecording):
|
||||
|
||||
```ts
|
||||
|
@@ -60,7 +60,7 @@ The `CameraDevice` type also contains other useful information describing a came
|
||||
Make sure to be careful when filtering out unneeded camera devices, since not every phone supports all camera device types. Some phones don't even have front-cameras. You always want to have a camera device, even when it's not the one that has the best features.
|
||||
:::
|
||||
|
||||
### `useCameraDevices` hook
|
||||
### The `useCameraDevices` hook
|
||||
|
||||
The react-native-vision-camera library provides a hook to make camera device selection a lot easier.
|
||||
|
||||
@@ -100,6 +100,14 @@ function App() {
|
||||
}
|
||||
```
|
||||
|
||||
### The `supportsPhotoAndVideoCapture` prop
|
||||
|
||||
Camera devices provide the `supportsPhotoAndVideoCapture` property which determines whether the device allows enabling photo- and video-capture at the same time. While every iOS device supports this feature, there are some older Android devices which only allow enabling one of each - either photo capture or video capture. (Those are `LEGACY` devices, see [this table](https://developer.android.com/reference/android/hardware/camera2/CameraDevice#regular-capture).)
|
||||
|
||||
:::note
|
||||
If you need photo- and video-capture for devices where `supportsPhotoAndVideoCapture` is `false`, you can fall back to snapshot capture (see [**"Taking Snapshots"**](https://cuvent.github.io/react-native-vision-camera/docs/guides/capturing#taking-snapshots)) instead.
|
||||
:::
|
||||
|
||||
### The `isActive` prop
|
||||
|
||||
The Camera's `isActive` property can be used to _pause_ the session (`isActive={false}`) while still keeping the session "warm". This is more desirable than completely unmounting the camera, since _resuming_ the session (`isActive={true}`) will be **much faster** than re-mounting the camera view.
|
||||
|
Reference in New Issue
Block a user