UI Video
Updated
A video element.
- Type
ent-ui-video- Script class
UIVideoEntity- Family
- UI
Overview
Section titled “Overview”A UI Video plays a video on a surface inside a UI: a trailer in a menu, a tutorial clip in a help panel, a live stream in a lobby screen. Its UI Video component (comp-ui-video) plays from src, a URL or one of the project’s video assets, and fits the picture into its box like an image. It plays the same sources as the world-space Video, including live streams through a Media Stream component, and a Chroma Key can make a green screen transparent.
A UI Video sits nested in a panel or layout, usually with play and volume controls beside it. A new one starts playing by itself, muted and looping, because browsers block autoplay with sound until the player has interacted. It never plays while you edit.
With a Signal Emitter on its entity, it reports UIVideo::ready { duration } when the first frame has loaded (in seconds, Infinity for a live stream), UIVideo::error { message }, and UIVideo::play, UIVideo::pause, UIVideo::stop and UIVideo::end.
Use a UI Video for video inside a UI panel. For a large screen that is part of the 3D world, use the world-space Video entity.
The props that matter most:
src: the video.autoplay,mutedandrepeat: start by itself (on), start muted (on), and'repeat'or play'once'.volumeandplaybackRate: the gain from 0 to 1, and the speed from 0.5 to 4.width,heightandobjectFit: the surface size in layout pixels (px), and'cover'(crop to fill) or'fill'(stretch).
From a script, play(), pause(), stop(), setVolume(volume), getVolume() and isPlaying() control playback.
Set it up
Section titled “Set it up”- Add a UI Video under a UI Panel or UI Layout. See Scenes and hierarchy.
- Set
src, awidthandheight, andrepeat. - Turn
autoplayoff if a button should start it. - Add a Signal Emitter to hear its playback events, and controls (buttons, a slider) beside it.
Examples
Section titled “Examples”Play and stop buttons
Section titled “Play and stop buttons”Goal: two buttons start the video with sound and stop it.
#pragma lifecycle(startup)
// Scene: a UI Video named 'Trailer' (autoplay off), and UI Buttons named 'Play Trailer'// and 'Stop Trailer' with Signal Emitters on 'trailer:play' and 'trailer:stop'.function startup() { const video = findEntity('Trailer').getComponent(UIVideoComponent);
on('trailer:play', (event) => { if (event.eventType !== EventType.UIButton.Press) return; video.setProps({ muted: false }); video.play(); });
on('trailer:stop', (event) => { if (event.eventType === EventType.UIButton.Press) video.stop(); });}How it works:
- Unmuting happens inside a press, after the player has interacted, so the browser allows sound.
play()starts or resumes;stop()stops and goes back to the start.
Show the length, offer a replay at the end
Section titled “Show the length, offer a replay at the end”Goal: show the clip’s length when it is ready, and a Replay button when it ends.
#pragma lifecycle(startup)
// Scene: a UI Video named 'Tutorial' (repeat: 'once', Signal Emitter: 'tutorial:video'),// a UI Label named 'Clip Info', and a UI Button named 'Replay' (Signal Emitter: 'tutorial:replay').function startup() { const video = findEntity('Tutorial').getComponent(UIVideoComponent); const info = findEntity('Clip Info').getComponent(UILabelComponent); const replay = findEntity('Replay'); replay.setEnabled(false);
on('tutorial:video', (event) => { if (event.eventType === EventType.UIVideo.Ready) { info.setProps({ text: `Tutorial · ${Math.round(event.data.duration)} s` }); } if (event.eventType === EventType.UIVideo.End) replay.setEnabled(true); if (event.eventType === EventType.UIVideo.Error) info.setProps({ text: 'The video could not load.' }); });
on('tutorial:replay', (event) => { if (event.eventType !== EventType.UIButton.Press) return; replay.setEnabled(false); video.stop(); video.play(); });}How it works:
- The listeners are registered in
startup: the firstreadyand autoplayplayevents arrive after Behaviors start, so none is missed. - With
repeat: 'once',UIVideo::endarrives at the end, and the Replay button appears. stop()thenplay()starts the clip again from the beginning.
A volume slider
Section titled “A volume slider”Goal: a slider beside the video sets its volume.
#pragma lifecycle(startup)
// Scene: a UI Video named 'Screen' and a UI Slider named 'Screen Volume'// with a Signal Emitter on 'screen:volume'.function startup() { const video = findEntity('Screen').getComponent(UIVideoComponent); const slider = findEntity('Screen Volume').getComponent(UISliderComponent);
slider.setProps({ text: 'Volume', min: 0, max: 100, step: 5, unit: '%' }); slider.setValue(Math.round(video.getVolume() * 100));
on('screen:volume', (event) => { if (event.eventType !== EventType.UISlider.Change) return; video.setProps({ muted: event.data.value === 0 }); video.setVolume(event.data.value / 100); });}How it works:
- The slider starts at the video’s current volume, read with
getVolume(). - Each step sets the gain from 0 to 1; moving off 0 unmutes the video, so the first drag is heard.
Components
Section titled “Components”What a new UI Video is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.
| Component | Type | Role | Per entity | What it does |
|---|---|---|---|---|
| Layer | comp-layer |
Required | One | Puts the entity on a render/raycast layer so cameras and rays can include or skip it. |
| Lock | comp-lock |
Required | One | Editor-only flag that stops the entity from being selected or moved. |
| Enable | comp-enable |
Required | One | Turns the entity and its children on or off: hides them and stops their behavior. |
| Transform | comp- |
Required | One | Position, rotation and scale of the entity, with optional editor-only per-axis locks. |
| UI Video | comp-ui-video |
Required | One | A video element. |
You can also add 7 optional components, such as AI Speech Capture, Attribution, Chroma Key, Media Stream, Networkable, Networkable Trait.
The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).
| Prop | Default | Range |
|---|---|---|
objectFit |
"cover" |
|
keep |
true |
|
volume |
1 |
0 ≤ x ≤ 1 |
muted |
true |
|
repeat |
"repeat" |
|
autoplay |
true |
|
playbackRate |
1 |
0.5 ≤ x ≤ 4 |
crossOrigin |
"anonymous" |
|
restart |
true |
Events
Section titled “Events”With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.
UIVideo::readyUIVideo::errorUIVideo::playUIVideo::pauseUIVideo::stopUIVideo::end
Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
A UI Video in a panel with a UI Toggle Button that plays and pauses it and a volume slider; the button's label follows the video's own play and pause events.
Press Play to start the video with sound, press again to pause, and drag the slider to change the volume. Drag outside the panel to orbit the camera, scroll to zoom.
From a script
Section titled “From a script”Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My UI Video.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My UI Video'); if (!(entity instanceof UIVideoEntity)) return;
// Its UI Video component holds the settings listed under Props. const component = entity.getComponent(UIVideoComponent); log('volume is', component.props.volume); component.setProps({ volume: 1 });}