A cinema screen with a play button
Updated
A button in the world plays and pauses a Video screen, and a Text sign follows its ready, play, pause and end events.
Click the amber button to play the film, and again to pause it. Drag elsewhere to orbit the camera, scroll to zoom.
A cinema screen with a play button
#pragma lifecycle(startup)
let screen;let status;
function startup() { screen = findEntity('Screen').getComponent(VideoComponent); status = findEntity('Status').getComponent(TextComponent); screen.setProps({ autoplay: false, muted: false, repeat: 'once' }); status.setProps({ text: 'Loading…' });
on('cinema/button', (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.play(); });
on('cinema', (event) => { switch (event.eventType) { case EventType.Video.Ready: status.setProps({ text: `Ready: ${Math.round(event.data.duration)} s` }); break; case EventType.Video.Play: status.setProps({ text: 'Now playing' }); break; case EventType.Video.Pause: status.setProps({ text: 'Paused' }); break; case EventType.Video.End: status.setProps({ text: 'The end' }); screen.stop(); break; case EventType.Video.Error: status.setProps({ text: 'This film cannot play' }); break; } });}How it works
Section titled “How it works”The script is explained step by step in A cinema screen with a play button.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
CinemaScreen.xrproj