* Move everything into package * Remove .DS_Store * Move scripts and eslintrc to package * Create CODE_OF_CONDUCT.md * fix some links * Update all links (I think) * Update generated docs * Update notice-yarn-changes.yml * Update validate-android.yml * Update validate-cpp.yml * Delete notice-yarn-changes.yml * Update validate-cpp.yml * Update validate-cpp.yml * Update validate-js.yml * Update validate-cpp.yml * Update validate-cpp.yml * wrong c++ style * Revert "wrong c++ style" This reverts commit 55a3575589c6f13f8b05134d83384f55e0601ab2.
10 KiB
id | title | sidebar_position | custom_edit_url |
---|---|---|---|
Camera | Camera | 0 | null |
A powerful <Camera>
component.
Read the VisionCamera documentation for more information.
The <Camera>
component's most important (and therefore required) properties are:
device
: Specifies theCameraDevice
to use. Get aCameraDevice
by using theuseCameraDevices()
hook, or manually by using theCamera.getAvailableCameraDevices()
function.isActive
: A boolean value that specifies whether the Camera should actively stream video frames or not. This can be compared to a Video component, whereisActive
specifies whether the video is paused or not. If you fully unmount the<Camera>
component instead of usingisActive={false}
, the Camera will take a bit longer to start again.
Example
function App() {
const devices = useCameraDevices('wide-angle-camera')
const device = devices.back
if (device == null) return <LoadingView />
return (
<Camera
style={StyleSheet.absoluteFill}
device={device}
isActive={true}
/>
)
}
Component
Hierarchy
-
PureComponent
<CameraProps
>↳
Camera
Methods
focus
▸ focus(point
): Promise
<void
>
Focus the camera to a specific point in the coordinate system.
Throws
CameraRuntimeError
When any kind of error occured while focussing. Use the code
property to get the actual error
Example
await camera.current.focus({
x: tapEvent.x,
y: tapEvent.y
})
Parameters
Name | Type | Description |
---|---|---|
point |
Point |
The point to focus to. This should be relative to the Camera view's coordinate system, and expressed in Pixel on iOS and Points on Android. * (0, 0) means top left. * (CameraView.width, CameraView.height) means bottom right. Make sure the value doesn't exceed the CameraView's dimensions. |
Returns
Promise
<void
>
Defined in
pauseRecording
▸ pauseRecording(): Promise
<void
>
Pauses the current video recording.
Throws
CameraCaptureError
When any kind of error occured while pausing the video recording. Use the code
property to get the actual error
Example
// Start
await camera.current.startRecording()
await timeout(1000)
// Pause
await camera.current.pauseRecording()
await timeout(500)
// Resume
await camera.current.resumeRecording()
await timeout(2000)
// Stop
const video = await camera.current.stopRecording()
Returns
Promise
<void
>
Defined in
resumeRecording
▸ resumeRecording(): Promise
<void
>
Resumes a currently paused video recording.
Throws
CameraCaptureError
When any kind of error occured while resuming the video recording. Use the code
property to get the actual error
Example
// Start
await camera.current.startRecording()
await timeout(1000)
// Pause
await camera.current.pauseRecording()
await timeout(500)
// Resume
await camera.current.resumeRecording()
await timeout(2000)
// Stop
const video = await camera.current.stopRecording()
Returns
Promise
<void
>
Defined in
startRecording
▸ startRecording(options
): void
Start a new video recording.
Records in the following formats:
- iOS: QuickTime (
.mov
) - Android: MPEG4 (
.mp4
)
Blocking
This function is synchronized/blocking.
Throws
CameraCaptureError
When any kind of error occured while starting the video recording. Use the code
property to get the actual error
Example
camera.current.startRecording({
onRecordingFinished: (video) => console.log(video),
onRecordingError: (error) => console.error(error),
})
setTimeout(() => {
camera.current.stopRecording()
}, 5000)
Parameters
Name | Type |
---|---|
options |
RecordVideoOptions |
Returns
void
Defined in
stopRecording
▸ stopRecording(): Promise
<void
>
Stop the current video recording.
Throws
CameraCaptureError
When any kind of error occured while stopping the video recording. Use the code
property to get the actual error
Example
await camera.current.startRecording()
setTimeout(async () => {
const video = await camera.current.stopRecording()
}, 5000)
Returns
Promise
<void
>
Defined in
takePhoto
▸ takePhoto(options?
): Promise
<PhotoFile
>
Take a single photo and write it's content to a temporary file.
Throws
CameraCaptureError
When any kind of error occured while capturing the photo. Use the code
property to get the actual error
Example
const photo = await camera.current.takePhoto({
qualityPrioritization: 'quality',
flash: 'on',
enableAutoRedEyeReduction: true
})
Parameters
Name | Type |
---|---|
options? |
TakePhotoOptions |
Returns
Promise
<PhotoFile
>
Defined in
getAvailableCameraDevices
▸ Static
getAvailableCameraDevices(): Promise
<CameraDevice
[]>
Get a list of all available camera devices on the current phone.
Throws
CameraRuntimeError
When any kind of error occured while getting all available camera devices. Use the code
property to get the actual error
Example
const devices = await Camera.getAvailableCameraDevices()
const filtered = devices.filter((d) => matchesMyExpectations(d))
const sorted = devices.sort(sortDevicesByAmountOfCameras)
return {
back: sorted.find((d) => d.position === "back"),
front: sorted.find((d) => d.position === "front")
}
Returns
Promise
<CameraDevice
[]>
Defined in
getCameraPermissionStatus
▸ Static
getCameraPermissionStatus(): Promise
<CameraPermissionStatus
>
Gets the current Camera Permission Status. Check this before mounting the Camera to ensure the user has permitted the app to use the camera.
To actually prompt the user for camera permission, use requestCameraPermission()
.
Throws
CameraRuntimeError
When any kind of error occured while getting the current permission status. Use the code
property to get the actual error
Returns
Promise
<CameraPermissionStatus
>
Defined in
getMicrophonePermissionStatus
▸ Static
getMicrophonePermissionStatus(): Promise
<CameraPermissionStatus
>
Gets the current Microphone-Recording Permission Status. Check this before mounting the Camera to ensure the user has permitted the app to use the microphone.
To actually prompt the user for microphone permission, use requestMicrophonePermission()
.
Throws
CameraRuntimeError
When any kind of error occured while getting the current permission status. Use the code
property to get the actual error
Returns
Promise
<CameraPermissionStatus
>
Defined in
requestCameraPermission
▸ Static
requestCameraPermission(): Promise
<CameraPermissionRequestResult
>
Shows a "request permission" alert to the user, and resolves with the new camera permission status.
If the user has previously blocked the app from using the camera, the alert will not be shown
and "denied"
will be returned.
Throws
CameraRuntimeError
When any kind of error occured while requesting permission. Use the code
property to get the actual error
Returns
Promise
<CameraPermissionRequestResult
>
Defined in
requestMicrophonePermission
▸ Static
requestMicrophonePermission(): Promise
<CameraPermissionRequestResult
>
Shows a "request permission" alert to the user, and resolves with the new microphone permission status.
If the user has previously blocked the app from using the microphone, the alert will not be shown
and "denied"
will be returned.
Throws
CameraRuntimeError
When any kind of error occured while requesting permission. Use the code
property to get the actual error
Returns
Promise
<CameraPermissionRequestResult
>