Skip to content

RupaPlayerElement

Copy as Markdown

<rupa-player>: a .rupaplay file mounted into the element, defined by importing @rupamotion/player/element (or loading its CDN script). The element is the player’s root container: the file’s markup is written into it.

Attributes (each change loads again; the element loads while it is in the page and has a src):

  • src: the file’s URL.
  • markup: keep, replace or auto (the default: an empty element gets the file’s markup), as MountFileOptions.
  • integrity: the file’s sha256-<base64> hash, checked before it is read.
  • cloak: present, the element is hidden until the file’s CSS is installed (or the load failed).

Events:

  • rupaready (bubbles): the file is mounted; event.detail.player is the Player.
  • rupaerror (does not bubble): the load failed and the element was left as it was; event.detail.error is the FileError, event.detail.src the src of that load (an older load replaced while in flight sends it too).

Taken out of the page, the element destroys its player; moved within the same document or shadow root, it keeps it.

<script type="module" src="https://cdn.jsdelivr.net/npm/@rupamotion/player/dist/element.js"></script>
<rupa-player src="/hero.rupaplay" cloak></rupa-player>
<script type="module">
const element = document.querySelector("rupa-player");
element.addEventListener("rupaready", (event) => event.detail.player.play("intro"));
element.addEventListener("rupaerror", (event) => console.warn(event.detail.error.code));
</script>
  • HTMLElement

readonly player: Player<string> | null

The player once the file is mounted; null before, after a failure, a change of the load or a disconnect.