webcamMedia
The user's camera, live in the layer.
webcamMedia(opts: MediaFitSlots & {
/** The selfie-mirror boolean prop. */
mirror: PropRef
/** The `getUserMedia` constraints to request the camera with. */
constraints: MediaStreamConstraints
/** The key the definition's `naturalSizeKey: {fixed}` uses (a webcam has no URL). */
naturalSizeKey: string
onError?: (
error: unknown,
info: {url: string | null; stage: 'acquire' | 'autoplay'},
) => void
}): MediaSurfaceHalf
Import media from shaders/std and use media.webcamMedia.
Asks for camera permission with your constraints. mirror is a boolean prop for a selfie flip that updates instantly. This word also accepts fit: 'none' to show the feed at its native pixel size. Set naturalSizeKey: {fixed: '<key>'} on the definition and pass the same key here. onError receives permission denials and playback failures.
Parameters
| Name | Type | Notes |
|---|---|---|
opts | `MediaFitSlots & { |
/** The selfie-mirror boolean prop. */
mirror: PropRef
/** The `getUserMedia` constraints to request the camera with. */
constraints: MediaStreamConstraints
/** The key the definition's `naturalSizeKey: {fixed}` uses (a webcam has no URL). */
naturalSizeKey: string
onError?: (error: unknown, info: {url: string \| null; stage: 'acquire' \| 'autoplay'}) => void
}` | |
Example
...webcamMedia({fit: p('objectFit'), mirror: p('mirror'), decode: 'srgb-linear-alpha-cut', constraints: {video: {facingMode: 'user'}}, naturalSizeKey: 'webcam'})
See also
videoMedia— A video from a URL prop, playing in the layer.imageMedia— An image from a URL prop, fitted into the layer.