videoMedia

A video from a URL prop, playing in the layer.

videoMedia(opts: MediaFitSlots & {
    /** The URL prop. */
    src: PropRef
    /** The loop prop, synced to the video each frame. */
    loop: PropRef
    /** Milliseconds to wait for the video's metadata before giving up. */
    metadataTimeoutMs: number
    onError?: (
  error: unknown,
  info: {url: string | null; stage: 'acquire' | 'autoplay'},
) => void
}): MediaSurfaceHalf

Import media from shaders/std and use media.videoMedia.

The video plays muted and inline. loop is a boolean prop. metadataTimeoutMs is how long to wait for the video's metadata before reporting a failure. Set naturalSizeKey: {fromProp: 'url'} on the definition. onError tells you whether loading ('acquire') or playback ('autoplay') failed.

Parameters

NameTypeNotes
opts`MediaFitSlots & {
/** The URL prop. */
src: PropRef
/** The loop prop, synced to the video each frame. */
loop: PropRef
/** Milliseconds to wait for the video's metadata before giving up. */
metadataTimeoutMs: number
onError?: (error: unknown, info: {url: string \| null; stage: 'acquire' \| 'autoplay'}) => void

}` | |

Example

...videoMedia({src: p('url'), fit: p('objectFit'), loop: p('loop'), decode: 'srgb-linear-alpha-cut', metadataTimeoutMs: 10000})

See also

  • imageMedia — An image from a URL prop, fitted into the layer.
  • webcamMedia — The user's camera, live in the layer.

Used by

VideoTexture