Skip to main content

Class: Camera

A powerful <Camera> component.

Read the VisionCamera documentation for more information.

The <Camera> component's most important (and therefore required) properties are:

  • device: Specifies the CameraDevice to use. Get a CameraDevice by using the useCameraDevices() hook, or manually by using the Camera.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, where isActive specifies whether the video is paused or not. If you fully unmount the <Camera> component instead of using isActive={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

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

NameTypeDescription
pointPointThe 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

Camera.tsx:289


getAvailableVideoCodecs

getAvailableVideoCodecs(fileType?): Promise<CameraVideoCodec[]>

Get a list of video codecs the current camera supports for a given file type. Returned values are ordered by efficiency (descending).

example

const codecs = await camera.current.getAvailableVideoCodecs("mp4")

throws CameraRuntimeError When any kind of error occured while getting available video codecs. Use the {@linkcode ParameterError.code | code} property to get the actual error

platform iOS

Parameters

NameType
fileType?VideoFileType

Returns

Promise<CameraVideoCodec[]>

Defined in

Camera.tsx:307


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

Camera.tsx:214


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

Camera.tsx:242


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

NameType
optionsRecordVideoOptions

Returns

void

Defined in

Camera.tsx:177


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

Camera.tsx:263


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

NameType
options?TakePhotoOptions

Returns

Promise<PhotoFile>

Defined in

Camera.tsx:120


takeSnapshot

takeSnapshot(options?): Promise<PhotoFile>

Take a snapshot of the current preview view.

This can be used as an alternative to takePhoto() if speed is more important than quality

throws CameraCaptureError When any kind of error occured while taking a snapshot. Use the code property to get the actual error

platform Android

example

const photo = await camera.current.takeSnapshot({
quality: 85,
skipMetadata: true
})

Parameters

NameType
options?TakeSnapshotOptions

Returns

Promise<PhotoFile>

Defined in

Camera.tsx:144


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

Camera.tsx:333


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

Camera.tsx:348


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

Camera.tsx:363


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

Camera.tsx:378


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>

Defined in

Camera.tsx:393