Skip to content

Video

Updated

A video file or HLS stream on a plane or a 360 sphere.

Type
ent-video
Script class
VideoEntity
Family
Media

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.
  • width and height: the screen’s size in metres; with sizing: 'auto' they become bounds and the screen takes the video’s own proportions.
  • autoplay, repeat and restart: start by itself in play, loop or play once, and start over or resume when the scene is entered again.
  • muted and volume: 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.
  • projection and side: equirectangular with side: 'back' for a 360 video watched from inside.

Scripts control it with play(), pause(), stop(), setVolume(v), getVolume() and isPlaying().

  1. Add a Video entity to the scene and name it, such as Cinema Screen.
  2. Set its src to a video file or an .m3u8 playlist.
  3. Set width and height in metres, or sizing to auto to keep the video’s proportions.
  4. Decide how it starts: keep autoplay for a backdrop, or turn it off for a video a script or the viewer starts. Turn controls on to give viewers a play button.
  5. Leave muted on for anything that autoplays; unmute it from a script after the viewer interacts.
  6. For a 360 video, set projection to equirectangular, side to back and width to the sphere’s radius.
  7. Add a Signal Emitter to hear Video::ready, Video::end and the other events in scripts.

Unmute and play the video when the viewer clicks the screen.

ClickToWatch.jx
#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 between pause() and play(); pause() keeps the position.

Play an intro clip, then start the rest of the experience when it ends.

IntroClip.jx
#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::ready carries the duration in seconds (Infinity for a live stream).
  • With repeat: 'once', Video::end arrives when the clip finishes by itself; the script hides the screen and raises its own story/next signal.
  • On Video::error, the story moves on anyway, so a missing file never blocks the viewer.

Switch the screen between several sources with the arrow keys.

Channels.jx
#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 src with setProps loads 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.

Make a green-screen recording stand in the scene, and switch the effect off on a signal.

Presenter.jx
#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.
  • detectedColor reads the colour that auto measured.
  • 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 src or crossOrigin reloads the video; other props apply to the playing one.

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-transform 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"

With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.

  • Video::ready
  • Video::error
  • Video::play
  • Video::pause
  • Video::stop
  • Video::end

Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.

Run it in the browser, read its scripts, and download it as an XR Creator project.

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.

VideoEntity.jx
#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 });
}