Video
Updated
A video file or HLS stream on a plane or a 360 sphere.
- Type
ent-video- Script class
VideoEntity- Family
- Media
Overview
Section titled “Overview”A Video entity plays a video on a flat screen or on a 360 sphere around the player: a cinema screen, a looping backdrop, a product clip, a 360 film. It plays a video file or an HLS stream (an .m3u8 playlist, the common format for streamed video). The picture is unlit and stays hidden until its first frame is ready, so no black plane flashes.
In play, a video with autoplay on starts once it can play. Leaving the scene pauses it; entering again starts it over, or resumes it when restart is off. In the editor, nothing autoplays: the first frame is shown paused, and the control bar, when controls is on, can play it while you author.
Pick a sibling when it fits better: a UI Video for a video inside a UI panel, an Image GIF or Lottie for a short silent loop, or an Audio entity for sound alone. To show a live camera, a shared screen or frames made by a script, keep the Video entity and add a Media Stream component to it.
The props that matter most, on its Video component (VideoComponent in scripts):
src: the video file or HLS playlist, as a URL or an asset from your project.widthandheight: the screen’s size in metres; withsizing: 'auto'they become bounds and the screen takes the video’s own proportions.autoplay,repeatandrestart: start by itself in play, loop or playonce, and start over or resume when the scene is entered again.mutedandvolume: on by default, because browsers only let a muted video start before the user has interacted.controls: a play/pause and volume bar under the screen.projectionandside:equirectangularwithside: 'back'for a 360 video watched from inside.
Scripts control it with play(), pause(), stop(), setVolume(v), getVolume() and isPlaying().
Set it up
Section titled “Set it up”- Add a Video entity to the scene and name it, such as
Cinema Screen. - Set its
srcto a video file or an.m3u8playlist. - Set
widthandheightin metres, orsizingtoautoto keep the video’s proportions. - Decide how it starts: keep
autoplayfor a backdrop, or turn it off for a video a script or the viewer starts. Turncontrolson to give viewers a play button. - Leave
mutedon for anything that autoplays; unmute it from a script after the viewer interacts. - For a 360 video, set
projectiontoequirectangular,sidetobackandwidthto the sphere’s radius. - Add a Signal Emitter to hear
Video::ready,Video::endand the other events in scripts.
Examples
Section titled “Examples”Start the film with sound on click
Section titled “Start the film with sound on click”Unmute and play the video when the viewer clicks the screen.
#pragma lifecycle(startup)
// Scene: a Video entity "Cinema Screen" (autoplay off) with a Selectable// and a Signal Emitter on the signal 'cinema'.let screen;
function startup() { screen = findEntity('Cinema Screen').getComponent(VideoComponent);
on('cinema', (event) => { if (event.eventType !== EventType.Selectable.Select) return; findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again if (screen.isPlaying()) { screen.pause(); } else { screen.setProps({ muted: false }); screen.setVolume(0.8); screen.play(); } });}How it works:
- A click is a user gesture, so the browser allows an unmuted start right after it.
setProps({ muted: false })turns the sound on without reloading;setVolume(0.8)sets the gain, from 0 to 1.isPlaying()lets one click toggle betweenpause()andplay();pause()keeps the position.
Play a clip once, then continue
Section titled “Play a clip once, then continue”Play an intro clip, then start the rest of the experience when it ends.
#pragma lifecycle(startup)
// Scene: a Video entity "Intro" with repeat: once, autoplay off,// and a Signal Emitter on the signal 'intro'.let intro;
function startup() { intro = findEntity('Intro').getComponent(VideoComponent);
on('intro', (event) => { if (event.eventType === EventType.Video.Ready) { log('Intro length:', event.data.duration.toFixed(1), 's'); } else if (event.eventType === EventType.Video.End) { findEntity('Intro').setEnabled(false); emit('story/next'); } else if (event.eventType === EventType.Video.Error) { log('Intro failed:', event.data.message); emit('story/next'); } });
on('story/start', () => intro.play());}How it works:
Video::readycarries thedurationin seconds (Infinityfor a live stream).- With
repeat: 'once',Video::endarrives when the clip finishes by itself; the script hides the screen and raises its ownstory/nextsignal. - On
Video::error, the story moves on anyway, so a missing file never blocks the viewer.
A channel switcher
Section titled “A channel switcher”Switch the screen between several sources with the arrow keys.
#pragma lifecycle(startup, update)
// Scene: a Video entity "TV".const CHANNELS = [ '/assets/video/news.mp4', '/assets/video/nature.mp4', 'https://example.com/live/index.m3u8',];let tv;let channel = 0;
function tune(step) { channel = (channel + step + CHANNELS.length) % CHANNELS.length; tv.setProps({ src: CHANNELS[channel] }); tv.play();}
function startup() { tv = findEntity('TV').getComponent(VideoComponent); tv.setProps({ src: CHANNELS[channel] });}
function update() { if (Input.keyboard.isKeyReleased(Key.ArrowRight)) tune(1); if (Input.keyboard.isKeyReleased(Key.ArrowLeft)) tune(-1);}How it works:
- Changing
srcwithsetPropsloads the new video; the other props stay as they are. play()right after asks for playback; it starts as soon as the new source can play.- File URLs and an HLS playlist mix freely in the list.
Show a presenter on a green screen
Section titled “Show a presenter on a green screen”Make a green-screen recording stand in the scene, and switch the effect off on a signal.
#pragma lifecycle(startup)
// Scene: a Video entity "Presenter" with a Chroma Key component (color: auto).let key;
function startup() { const presenter = findEntity('Presenter'); key = presenter.getComponent(ChromaKeyComponent);
on('presenter/key-off', () => key.setEnabled(false)); on('presenter/key-on', () => key.setEnabled(true)); on('presenter/show-key', () => log('Keyed colour:', key.detectedColor));}How it works:
- A Chroma Key on the Video entity makes one colour transparent; with
color: 'auto'it measures the green or blue screen from the video itself. setEnabled(false)shows the original video again; changing its props never reloads or restarts the video.detectedColorreads the colour thatautomeasured.
- Each playing video uploads a new picture to the GPU on every frame it advances. Several large videos at once are costly on phones and headsets: pause what is out of sight.
stop()returns to the start and, for an HLS stream, stops loading;pause()keeps the position.- Changing
srcorcrossOriginreloads the video; other props apply to the playing one.
Components
Section titled “Components”What a new 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. |
| Video | comp-video |
Required | One | A video file or HLS stream on a plane or a 360 sphere. |
You can also add 21 optional components, such as AI Speech Capture, Animation Graph, Animation Timeline, Attribution, Billboard, Chroma Key.
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 |
|---|---|---|
repeat |
"repeat" |
|
width |
1.6 |
0 ≤ x ≤ 10000 |
height |
0.9 |
0 ≤ x ≤ 10000 |
autoplay |
true |
|
muted |
true |
|
volume |
1 |
0 ≤ x ≤ 1 |
playsInline |
true |
|
crossOrigin |
"anonymous" |
|
controls |
false |
|
restart |
true |
|
projection |
"planar" |
|
side |
"double" |
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.
Video::readyVideo::errorVideo::playVideo::pauseVideo::stopVideo::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 presenter filmed on a green screen is keyed into the scene by a Chroma Key on the Video entity; a script sets the key colour and switches the key, a blue key or automatic measurement from the keyboard.
Click the scene, then press K to turn the key off and on, B to key a blue screen instead, and A to let the key measure the screen colour itself. Drag 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 Video.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My Video'); if (!(entity instanceof VideoEntity)) return;
// Its Video component holds the settings listed under Props. const component = entity.getComponent(VideoComponent); log('width is', component.props.width); component.setProps({ width: 2.4 });}