Hosted script
The recommended way to embed the player: one script tag and one element, right in your own page.
The player goes straight into your page, not into a frame, and your page can follow what it does. The script loads from Spine, so it always runs the latest player release.
Quick start
Ask Spine to set up your site
Tell Spine you’ll use the hosted script, and send:
- the origins of the pages that will show the player, such as
https://www.example.com, and the ones you test on, such ashttp://localhost:5173 - every domain those pages run on, staging and local ones included: the player’s licence has to cover them
Spine sends you your site’s embed ID and the slugs of its channels.
Load the script
Add this once per page, in the <head>:
<script type="module" src="https://player.spinectrl.com/embed.js"></script>Add the player
Put the element where the player goes, with your embed ID and a channel’s slug:
<spine-player embed-id="01jdm8q3vz5k7r2x9c4n6b8t0w" channel="spor-1"></spine-player>Leave out channel to play your site’s default channel. The player is as wide as its container, and 16:9.
Open your page
The player starts on its own, muted, and shows “Tap to unmute”: browsers don’t allow autoplay with sound. If it shows a message instead, look it up in Troubleshooting.
Follow what the player does
The element fires a spine-state event whenever what the player shows changes. For example, to show a “Live” badge only while the player plays:
<span id="live-badge" hidden>Live</span>
<spine-player embed-id="01jdm8q3vz5k7r2x9c4n6b8t0w" channel="spor-1"></spine-player>
<script>
const badge = document.getElementById("live-badge");
document.querySelector("spine-player").addEventListener("spine-state", (event) => {
badge.hidden = event.detail.status !== "playing";
});
</script>
What the event tells you
The event bubbles and crosses shadow DOM boundaries. Its detail is the player’s state:
| Field | Type | Meaning |
|---|---|---|
status |
string | idle, loading, playing, paused, switching, reconnecting, offAir, unavailable, denied, error or disposed. |
problem |
string or null |
Why it’s denied or stuck: forbidden, disabled, protected, config or media. |
muted |
boolean | Whether the sound is off. The player starts muted. |
pictureInPicture |
boolean | Whether the video shows in the browser’s picture-in-picture window. |
The player reference says what each status means, what the viewer sees, and what your page might do about it.
Control the player
The element takes commands from your page, as a viewer’s controls would: play(), pause(), mute(), unmute(), setChannel(channel), requestPictureInPicture() and exitPictureInPicture(). For example, buttons of your own that switch channel and open picture-in-picture:
<button id="spor-2">Spor 2</button>
<button id="pip">Picture-in-picture</button>
<spine-player embed-id="01jdm8q3vz5k7r2x9c4n6b8t0w" channel="spor-1"></spine-player>
<script>
const player = document.querySelector("spine-player");
document.getElementById("spor-2").addEventListener("click", () => player.setChannel("spor-2"));
document.getElementById("pip").addEventListener("click", () => player.requestPictureInPicture());
</script>
setChannel switches in place, as the channel selector does, whether or not the selector shows. The player reference says what each command does.
Attributes
Only embed-id is required. The rest change how the player plays, and each one you leave out uses your site’s default, which Spine sets for you, except the language, which follows the viewer’s browser.
Every attribute
| Attribute | Values | Default | What it does |
|---|---|---|---|
embed-id |
your site’s embed ID, with or without emb_ |
required | The site. Without it, the element plays nothing. |
channel |
the slug or ID of a channel assigned to the site | the site’s default channel | The channel. channel-id is its older name, for a channel ID, and still works. See Channels. |
channel-selector |
present, or "false" |
off | The channel selector, where Spine allows it for your site. "false" turns it off. |
host |
the player host | where embed.js came from |
Leave it out with the hosted script. |
latency |
auto, low, balanced, smooth |
site default | How far behind live on standard-latency streams. |
live-pause |
off, live, shift |
site default | What pausing does. |
data-saver |
present, or "false" |
site default | Present turns the data saver on, and data-saver="false" turns it off. |
max-quality |
720, 720p, or all |
site default | The highest quality offered, by height. all offers every quality, even above your site’s default. |
fill |
present | off | Fill the element’s height too, rather than 16:9. Give the element a height. |
debug |
present, or "false" |
site default | The Stream Info and Network & Latency panels, for troubleshooting. debug="false" turns off a site default. |
language |
en, tr |
the viewer’s | The language the player speaks to viewers. Left out, the viewer’s browser language decides. |
The player reference says what each setting does in detail, and how site defaults work.
- Changing an attribute starts the player over with the new settings. A channel a viewer picks in the channel selector doesn’t change the element’s attributes.
- Removing the element from the page stops the player and releases everything it held. Putting it back starts a new one.
- The element can come before or after the script tag. The browser upgrades it once the script has run.
React, Vue, Angular and Svelte
Load embed.js once in your HTML shell, and render <spine-player> in your components. The framework creates and removes the element, and the player starts and stops with it. When the npm packages are published, you can use their components instead.
Examples
import { useEffect, useRef } from "react";
type PlayerState = { status: string; problem: string | null; muted: boolean };
type LivePlayerProps = {
embedId: string;
/** The channel's slug or ID. Left out, the site's default channel plays. */
channel?: string;
latency?: "auto" | "low" | "balanced" | "smooth";
onState?: (state: PlayerState) => void;
};
export function LivePlayer({ embedId, channel, latency, onState }: LivePlayerProps) {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (element === null || onState === undefined) return;
const listener = (event: Event) => onState((event as CustomEvent<PlayerState>).detail);
element.addEventListener("spine-state", listener);
return () => element.removeEventListener("spine-state", listener);
}, [onState]);
return <spine-player ref={ref} embed-id={embedId} channel={channel} latency={latency} />;
}TypeScript needs to know the element. Add a declaration file, such as spine-player.d.ts:
import type { DetailedHTMLProps, HTMLAttributes } from "react";
type SpinePlayerAttributes = DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement> & {
"embed-id": string;
channel?: string | undefined;
"channel-selector"?: "true" | "false" | undefined;
host?: string | undefined;
latency?: "auto" | "low" | "balanced" | "smooth" | undefined;
"live-pause"?: "off" | "live" | "shift" | undefined;
"data-saver"?: "true" | "false" | undefined;
"max-quality"?: string | undefined;
debug?: "true" | "false" | undefined;
fill?: "" | undefined;
language?: "en" | "tr" | undefined;
};
declare module "react" {
namespace JSX {
interface IntrinsicElements {
"spine-player": SpinePlayerAttributes;
}
}
}With React 18’s types, declare the same interface under declare global { namespace JSX { … } } instead.
Pass attributes as strings. React may write a boolean false as the attribute "false", which for fill still counts as present, so add fill="" only when you want it. For the channel selector, channel-selector="true" turns it on and "false" turns it off.
In Next.js, add the script to your root layout with a plain tag, <script type="module" src="https://player.spinectrl.com/embed.js" />, inside <head>. The element renders on the server as an empty tag and starts in the browser.
Tell Vue that spine-player is a custom element, so it doesn’t look for a Vue component. With Vite:
// vite.config.ts
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
vue({
template: { compilerOptions: { isCustomElement: (tag) => tag === "spine-player" } },
}),
],
});In Nuxt, set the same option as vue.compilerOptions.isCustomElement in nuxt.config.ts, and add the script under app.head.script as { src: "https://player.spinectrl.com/embed.js", type: "module" }.
<script setup lang="ts">
// `channel` is the channel's slug or ID. Left out, the site's default channel plays.
defineProps<{ embedId: string; channel?: string }>();
const emit = defineEmits<{ state: [{ status: string; problem: string | null; muted: boolean }] }>();
</script>
<template>
<spine-player
:embed-id="embedId"
:channel="channel"
@spine-state="emit('state', $event.detail)"
/>
</template>Allow custom elements in the component that uses it:
import { CUSTOM_ELEMENTS_SCHEMA, Component, EventEmitter, Input, Output } from "@angular/core";
@Component({
selector: "app-live-player",
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<spine-player
[attr.embed-id]="embedId"
[attr.channel]="channel"
(spine-state)="state.emit($any($event).detail)"
></spine-player>
`,
})
export class LivePlayerComponent {
@Input({ required: true }) embedId!: string;
/** The channel's slug or ID. Left out, the site's default channel plays. */
@Input() channel?: string;
@Output() state = new EventEmitter<{ status: string; problem: string | null; muted: boolean }>();
}Add the script tag to src/index.html.
<script lang="ts">
export let embedId: string;
/** The channel's slug or ID. Left out, the site's default channel plays. */
export let channel: string | undefined = undefined;
</script>
<spine-player
embed-id={embedId}
{channel}
on:spine-state={(event) => console.log(event.detail.status)}
></spine-player>Add the script tag to src/app.html in SvelteKit, or index.html with Vite.
JavaScript API
To create players from code rather than with the element, import SpinePlayer from the script.
Create players from code
<div id="player"></div>
<script type="module">
import { SpinePlayer } from "https://player.spinectrl.com/embed.js";
const player = SpinePlayer.create("player", {
embedId: "01jdm8q3vz5k7r2x9c4n6b8t0w",
channel: "spor-1",
channelSelector: true,
latency: "low",
onState: (state) => console.log("player", state.status, state.problem),
});
// Later, when the player should go:
// player.destroy();
</script>SpinePlayer.create(container, options) takes:
container: the element to put the player in, or itsid. The player is appended to it. Use an empty element of its own.options: as in the player reference.embedIdis required.channelis optional: without it, your site’s default channel plays.channelId, its older name, still works.hostis the host the script came from, unless you name another.
It returns the player at once and loads the player’s code in the background:
| Member | What it does |
|---|---|
destroy() |
Stops media, timers and listeners, and removes the player. Safe to call more than once. |
state() |
The current state, { status, problem, muted, pictureInPicture }, as onState reports it. |
ready |
A promise that settles once the player’s code has loaded, or failed to load. It never rejects; check state() afterwards. |
| Commands | play(), pause(), mute(), unmute(), setChannel(channel), requestPictureInPicture() and exitPictureInPicture(), as on the element (see Commands). Before the player’s code has loaded they do nothing, as while nothing plays, and requestPictureInPicture() returns false; setChannel() then picks the channel the player starts on. |
create throws if container is an id that matches no element, or an element in another document, such as one inside an iframe. Load the script in that frame’s own page instead.
The script also sets window.SpinePlayer to the same object, for code that can’t use import. Module scripts run after the page has been parsed, so read window.SpinePlayer only after embed.js has run: from another type="module" script placed after it, or after the window’s load event.
SpinePlayer.serveGrants(iframe, getGrant) is for a page that frames the embed in an <iframe> instead: it answers the iframe’s grant requests on a site with customer grants. See Iframe embed.
Protected playback
Only for a site on customer grants. On any other site, you have nothing to add.
Hand the player each viewer's grant
On a site with customer grants (see Security and access), give the player a getGrant function that gets each viewer’s grant from your backend (see Your endpoint for the player):
<spine-player embed-id="01jdm8q3vz5k7r2x9c4n6b8t0w" channel="spor-1"></spine-player>
<script type="module">
async function getGrant({ channel }) {
const response = await fetch("/api/spine/grant", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ channel }),
});
return response.ok ? (await response.json()).grant : null;
}
document.querySelector("spine-player").getGrant = getGrant;
</script>- On the element,
getGrantis a property, not an attribute. You can set it at any time, before or after the element is defined, and replace it whenever you like: the player reads it each time it needs a grant, so changing it doesn’t start the player over. - In a single-page app, set the property on the element your framework renders, as you would any DOM property: in React, through a ref, from an effect.
- With
SpinePlayer.create, pass it as thegetGrantoption. - It gets
{ embedId, channel, reason }: your site’s embed ID in full, withemb_; the slug of the channel the player plays, even when the embed names it by ID or names none, which your backend needs only to limit a grant to one channel; andreason,"start"or"renew". It returns a promise of the grant, or ofnullwhen the viewer may not watch. A promise that rejects counts asnull. - It’s called when the player starts, about every four minutes while it plays, when a viewer switches channel, and when the player has to restart the stream. Answer within a few seconds.
Without a grant, the player plays nothing, reports the state denied with the problem protected, and shows “Your access to this stream couldn’t be confirmed”. It asks again about a minute later.
On iPhones and iPads before iOS 17.1, Safari plays the stream itself, and the player in your own page can’t renew a protected stream’s credentials mid-stream there. Playback pauses and resumes by itself every few minutes. The iframe embed renews them without a pause, so it’s the better choice for protected playback on those devices.
Content Security Policy
Only if your pages send a Content-Security-Policy header.
What the player needs in your policy
Add these, besides what your page already allows:
| Directive | Add | For |
|---|---|---|
script-src |
https://player.spinectrl.com |
embed.js and the player’s code |
connect-src |
https://player.spinectrl.com https://*.theo.live |
the player’s configuration, licence and sessions, and Dolby’s streams |
media-src |
blob: |
the video element, which plays from a media source the player builds |
worker-src |
blob: https://player.spinectrl.com |
the video engine’s workers |
If Spine plays a partner’s HLS stream on your site, its CDN’s host has to be in connect-src too. Ask Spine for it.
The player’s styles don’t need style-src 'unsafe-inline' in current browsers. Safari before 16.4 is the exception: there the player adds a <style> element, which a strict style-src blocks.
Referrer policy
Spine’s delivery serves media only to requests whose referrer is one of your site’s origins, so your pages must send one:
- The browser’s default (
strict-origin-when-cross-origin) works, and so doorigin,strict-originandorigin-when-cross-origin. no-referrerandsame-originsend no referrer to Dolby, so every viewer is refused. That includes<meta name="referrer" content="no-referrer">and aReferrer-Policyheader your server or CDN adds.
Before you launch
- Use a separate site for each environment. Your production website, staging website and app each get their own site and embed ID. Don’t register a staging or local origin on a production site.
- Serve your pages over
https. Spine registers onlyhttpsorigins, apart fromhttp://localhostfor testing. - Tell Spine before you move to a new domain. A page on an origin Spine hasn’t registered can’t play, and a new origin can take several minutes to reach every edge of Dolby’s delivery.
- Keep sending a referrer (see Referrer policy).
- Test on the devices your audience uses.
More
Change the player's size or shape
Without fill, the player is as wide as its container and 16:9 tall. To use another shape, set --spine-player-aspect-ratio on the element or any ancestor:
spine-player {
--spine-player-aspect-ratio: 4 / 3;
}With fill, the player takes the height you give the element:
<spine-player
fill
style="height: 70vh"
embed-id="01jdm8q3vz5k7r2x9c4n6b8t0w"
channel="spor-1"
></spine-player>Your page’s CSS doesn’t reach inside the player, so styling the element itself, its size, margins and border radius, is all you need.
Show several players on one page
Each element or create call is its own player, with its own channel and, if you ask for it, its own channel selector. They all start muted, so they don’t play over each other until a viewer unmutes one. Each one downloads video, so on phones, consider creating a player only once its section is on screen.
What the script costs your page
The script is small, about 1.8 KB compressed. The player itself, about 650 KB compressed and nearly all of it the video engine, loads only when the page creates a player. So it’s fine to include the script on pages that only sometimes show a player.
embed.js always loads the release Spine currently serves. Browsers and CDNs keep it for up to a minute.