@bitmovin/player-integration-webxr
v1.2.0
Published
WebXR integration for immersive video playback with the Bitmovin Player
Readme
Bitmovin Player WebXR Integration
Immersive video for the Bitmovin Web Player: 360°, 180° and partial dome projections, mono or stereo, rendered through A-Frame on a desktop, in a headset or on a phone.
The VR UI elements ship in the same package, as
@bitmovin/player-integration-webxr/ui/*.
Full documentation and API reference: https://cdn.bitmovin.com/player/web/integration/webxr/1/docs/index.html
Sample apps:
webxr: the integration with the default player UI.webxr-amp-skin: the integration with the AMP player UI skin.
Install
npm install @bitmovin/player-integration-webxr aframe@^1.8.0 bitmovin-player@^8.280.0Release candidates are published under the next tag:
npm install @bitmovin/player-integration-webxr@next.
aframe and bitmovin-player are peer dependencies. Both register page
globals and must be on the page exactly once, so the application supplies them.
Without a bundler, load the UMD builds after A-Frame and the player. The
library is then bitmovin.player.webxr, the UI elements are
bitmovin.player.webxr.ui:
<script src="https://aframe.io/releases/1.8.0/aframe.min.js"></script>
<script src="https://cdn.bitmovin.com/player/web/8/bitmovinplayer.js"></script>
<script src="node_modules/@bitmovin/player-integration-webxr/dist/bitmovin-player-webxr.umd.cjs"></script>
<script src="node_modules/@bitmovin/player-integration-webxr/dist/ui/bitmovin-player-webxr-ui.umd.cjs"></script>
<script>
const { BitmovinWebXR } = bitmovin.player.webxr;
const { createControlBar } = bitmovin.player.webxr.ui;
</script>Many static servers send .cjs files with a type the browser does not run.
Serve them as JavaScript, or copy them to a .js name.
Browser support
A-Frame 1.8 sets the minimum. The three.js it bundles uses class static blocks, which need Safari 16.4, Chrome 94 or Firefox 93. On iOS and iPadOS, Safari follows the OS version, so 16.4 is also the minimum OS. An older browser cannot parse A-Frame.
Quick start
The application creates and configures the player. The integration attaches to it, gives it a video element of its own, and draws that element onto a projection surface in the scene.
<div id="player-container"></div>
<a-scene id="scene">
<a-camera id="cam" position="0 0 0" wasd-controls-enabled="false"></a-camera>
</a-scene>Leave the player container unstyled. The player moves the integration's video
element into it, and Safari's native HLS limits the quality to the element's
rendered size, so nothing may shrink it (zoom, transform, scripts that
change its inline style); the integration keeps it large, transparent and
click-through itself.
import "aframe";
import { Player } from "bitmovin-player";
import { BitmovinWebXR } from "@bitmovin/player-integration-webxr";
const container = document.getElementById("player-container");
const scene = document.getElementById("scene");
if (!container || !scene) {
throw new Error("index.html is missing #player-container or #scene.");
}
const player = new Player(container, { key: "YOUR-PLAYER-KEY", ui: false });
const xr = await BitmovinWebXR.create(player, scene, {
projection: { horizontalDeg: 360, verticalDeg: 180 },
stereo: { layout: "mono" },
background: { mode: "color", color: "#101018" },
});
await player.load({ hls: "https://example.com/stream.m3u8" });Lifecycle
- Call
BitmovinWebXR.create()before the player's firstload(), and await it. It rejects if the player already has a source, if one is loaded while the scene loads, if the scene has no camera, or if the scene does not load. xr.destroy()removes everything the integration added to the scene. It does not touch the player.- After
destroy(), the player stays bound to the removed video element. It is not reusable: destroy it too, or keep the integration as long as the player.
Configuration
Every section of the configuration is optional. A key left out takes its
DEFAULT_* value (DEFAULT_PROJECTION, DEFAULT_CAPTIONS, …). The set…()
methods merge onto the configuration in effect, except setBackground(), which
replaces it. A key left out or undefined keeps its current value.
Out-of-range numbers are clamped, not rejected. Every get…() returns a copy.
The keys, their ranges and the methods are documented in the package's type
declarations.
Events
import { WebXREvent } from "@bitmovin/player-integration-webxr";
xr.on(WebXREvent.FrameStateChanged, ({ hasFrame }) => {
spinner.visible = !hasFrame;
});| Event | Payload | When |
| ------------------------------ | -------------------------------------------------- | ------------------------------------------- |
| WebXREvent.FrameStateChanged | { hasFrame: boolean } | The surfaces start or stop showing a frame. |
| WebXREvent.InputChanged | InputState: { mouse, touch, gaze, … } booleans | The live input models change. |
| WebXREvent.PointerMiss | { ray?: { origin, direction } } | A press in a session hits no ray target. |
hasFrame is false from a load() until the first frame. It does not say why
there is no frame: listen for the player's Error event as well.
Each event also fires on the scene as a DOM event of the same name, with the
payload as detail. destroy() removes every handler added with on().
Captions
The caption panel draws the cues the player emits. Which track is on is the
application's decision, through player.subtitles.
Device orientation
Looking around by tilting a phone or tablet needs the orientation sensors. The
integration never asks for them itself. Ask from a click handler:
const ask = () => {
xr.requestDeviceOrientation().then((result) => {
// "granted" | "denied" | "unsupported" | "needs-gesture"
if (result === "needs-gesture") {
window.addEventListener("click", ask, { once: true });
}
}, console.warn);
};
window.addEventListener("click", ask, { once: true });- Use
click, on every platform. WebKit does not acceptpointerdownas the gesture, and Chrome plans to require one too. - Re-arm on
"needs-gesture". A click whose user activation was already used (entering VR, going fullscreen) asks nothing, and that must not use up your only attempt.
An origin that already granted access resolves without a prompt.
VR UI elements
A control bar, a compass, a buffering overlay and a recenter rig, each usable
on its own. See ui/README.md.
import { createControlBar } from "@bitmovin/player-integration-webxr/ui/control-bar";
const bar = createControlBar(scene, { player, xr });Pan guard
A-Frame's look-controls turns every drag into camera rotation, also a drag on
a slider. create() puts a pan guard on the scene: a drag that starts on an
entity with PAN_GUARD_CLASS does not turn the camera. The UI's control bar
marks itself. Mark your own panels the same way:
import { PAN_GUARD_CLASS, PAN_GUARD_COMPONENT } from "@bitmovin/player-integration-webxr";
panel.classList.add(PAN_GUARD_CLASS);
// Or guard more entities by selector:
scene.setAttribute(PAN_GUARD_COMPONENT, "regions", ".my-panel");A scene that has its own PAN_GUARD_COMPONENT before create() keeps it.
destroy() removes the guard create() put on, unless the application has
changed its regions or margin since.
Development
See CONTRIBUTING.md.
