Skip to content
Spine Media Player
Esc
↑↓navigate↵open⌘Jpreview
On this page

Iframe embed

One tag and no JavaScript: the player in a frame, in any website, CMS or template language.

The player runs on Spine’s host, in its own frame, so nothing on your page can interfere with it. Your page can’t follow what the player does, though. For that, use the hosted script, which we recommend.

Quick start

Ask Spine to set up your site

Tell Spine you’ll use an iframe, 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 as http://localhost:5173.

Spine sends you your site’s embed ID and the slugs of its channels.

Paste the tag

Put this where the player goes, with your embed ID and a channel’s slug:

<iframe
  src="https://player.spinectrl.com/embed/01jdm8q3vz5k7r2x9c4n6b8t0w?channel=spor-1"
  title="Live stream"
  allow="autoplay; fullscreen"
  allowfullscreen
  style="width: 100%; aspect-ratio: 16 / 9; border: 0"
></iframe>

Leave out ?channel=spor-1 to play your site’s default channel.

Why each attribute is there
Attribute Why
allow="autoplay; fullscreen" Lets the player start on its own (muted) and go fullscreen. Without autoplay, viewers have to press play. Without fullscreen, the fullscreen button does nothing.
allowfullscreen The same permission for older browsers.
title Names the frame for screen readers. Use something that describes the stream, such as the channel’s name.
style The player fills the frame, so the frame’s size is the player’s size. See Sizing.

Don’t add sandbox. The player needs scripts, fullscreen and its own origin to reach Spine’s host, and a sandbox takes them away.

Open your page

The player starts on its own, muted, and shows “Tap to unmute”: browsers don’t allow autoplay with sound. If the frame stays empty, Spine hasn’t registered your page’s origin yet, or your page’s own headers block the frame (see Before you launch). If the player shows a message, look it up in Troubleshooting.

The embed URL

https://player.spinectrl.com/embed/<embedId>
https://player.spinectrl.com/embed/<embedId>?channel=<channel>
  • embedId: your site’s embed ID, as in the links Spine gives you. The whole ID, with its emb_ prefix, works too.
  • channel: the channel to play, by its slug, such as spor-1, or by its channel ID, chan_ and 26 characters. Without it, your site’s default channel plays. URLs made before slugs name the channel as channelId=chan_…, which still works.
  • channels: 1 adds the channel selector, where Spine allows it for your site.

The URL stays the same for the life of your integration. Spine releases player updates behind it, so you never edit your pages for a new player version.

Sizing

The player always fills its frame, so you size the <iframe>. Keep the frame at the video’s shape, 16:9, or the picture gets black bars. Below about 320 pixels wide the controls get cramped, so don’t make it smaller than that.

More layouts

Full width, 16:9 (the quick start’s tag):

.live-player {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
}

A maximum width, centered:

.live-player {
  display: block;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  border: 0;
}

Filling a container whose size you already control, such as a hero area or a grid cell:

.player-slot {
  position: relative;
  height: 60vh;
}
.player-slot iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

Player settings on the URL

Optional. Add them to the embed URL to change how the player plays, such as &latency=low&maxquality=720. 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 setting
Parameter Values Player default What it does
latency auto, low, balanced, smooth auto How far behind live it plays on standard-latency streams. low is closest to live, smooth buffers most. auto moves between them as the network allows. Low-latency streams keep their own latency.
livepause off, live, shift live What pausing does. off: no pausing (no pause button). live: pause, then play jumps back to live. shift: play carries on where it paused, while the broadcast still holds that point.
datasaver 1, 0 1 1 caps quality to what the player’s size on screen needs, lowers it while the page is hidden, and stops downloading when nobody is watching or listening. 0 turns that off.
maxquality a height such as 720, or all all The highest quality the player offers, by picture height. all offers every quality, even above your site’s default.
debug 1, 0, open 0 1 adds the Stream Info and Network & Latency panels and a button for them. open also opens Stream Info. For troubleshooting, not for viewers.
language en, tr the viewer’s The language the player speaks to viewers: English or Turkish. Left out, the viewer’s browser language decides, and English if it’s neither. A site has no default for it.

Example: closest to live, nothing above 720p.

https://player.spinectrl.com/embed/01jdm8q3vz5k7r2x9c4n6b8t0w?channel=spor-1&latency=low&maxquality=720

These settings change how the player plays, never what it’s allowed to play. Viewers can edit the URL, so none of them is a restriction. Spine’s own delivery limits, such as a channel’s maximum bitrate, apply whatever the URL says.

Several channels on one site

Each iframe plays one channel at a time. To show two channels at once, use two iframes. To let viewers switch, add channels=1 to the URL, or use buttons of your own.

Let viewers switch channels

With channels=1, the player shows its channel selector: viewers pick a channel from a menu in the control bar, beside the quality menu, and the player switches in place. It shows only where Spine allows it for your site, and only when your site has more than one channel. See Channel selector.

https://player.spinectrl.com/embed/01jdm8q3vz5k7r2x9c4n6b8t0w?channel=spor-1&channels=1

Or use buttons of your own, which change the iframe’s src:

<nav>
  <button data-channel="spor-1">Spor 1</button>
  <button data-channel="spor-2">Spor 2</button>
</nav>
<iframe
  id="live"
  title="Live stream"
  allow="autoplay; fullscreen"
  allowfullscreen
  style="width: 100%; aspect-ratio: 16 / 9; border: 0"
></iframe>

<script>
  const PLAYER_HOST = "https://player.spinectrl.com";
  const EMBED_ID = "01jdm8q3vz5k7r2x9c4n6b8t0w";
  const frame = document.getElementById("live");

  function play(channel) {
    const query = new URLSearchParams({ channel });
    frame.src = `${PLAYER_HOST}/embed/${encodeURIComponent(EMBED_ID)}?${query}`;
  }

  document.querySelectorAll("[data-channel]").forEach((button) => {
    button.addEventListener("click", () => play(button.dataset.channel));
  });
  play("spor-1");
</script>

A channel has to be assigned to your site to play. A channel that isn’t shows “This player can’t play this channel”.

Protected playback

Only for a site on customer grants. On any other site, the iframe needs nothing more.

Answer the player's grant requests

On a site with customer grants (see Security and access), the player in the iframe asks your page for each viewer’s grant, over postMessage, and your page answers with a grant from your backend (see Your endpoint for the player).

With Spine’s hosted script on the page, SpinePlayer.serveGrants(iframe, getGrant) answers for you:

<iframe
  id="live"
  src="https://player.spinectrl.com/embed/01jdm8q3vz5k7r2x9c4n6b8t0w?channel=spor-1"
  title="Live stream"
  allow="autoplay; fullscreen"
  allowfullscreen
  style="width: 100%; aspect-ratio: 16 / 9; border: 0"
></iframe>

<script type="module">
  import { SpinePlayer } from "https://player.spinectrl.com/embed.js";

  SpinePlayer.serveGrants(document.getElementById("live"), async ({ 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;
  });
</script>
  • getGrant gets { embedId, channel, reason }: your site’s embed ID in full, with emb_; 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; and reason, "start" or "renew". It returns a promise of the grant, or of null when the viewer may not watch.
  • 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 10 seconds: after that, the player takes it as no grant. A promise that rejects counts as no grant too.
  • serveGrants returns a function that stops answering. Call it when your page removes the iframe, as in a single-page app.
  • With the npm package, import serveGrants from @spinemedia/player instead (see npm packages).

Without a grant, the player plays nothing and shows “Your access to this stream couldn’t be confirmed”. It asks again about a minute later.

Answer without Spine's script

A page that loads neither the hosted script nor the npm package can answer the player itself:

  1. The player posts { type: "spine:grant-request", id, embedId, channel, reason } to the page that frames it.
  2. The page answers by posting { type: "spine:grant", id, grant } to the iframe’s window, with the request’s id, and grant set to the grant, or to null if it has none.
const PLAYER_ORIGIN = "https://player.spinectrl.com";
const frame = document.getElementById("live");

async function grantFor(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;
}

window.addEventListener("message", async (event) => {
  // Only your own iframe's player, from the player's origin.
  if (event.source !== frame.contentWindow || event.origin !== PLAYER_ORIGIN) return;
  const request = event.data;
  if (request?.type !== "spine:grant-request") return;
  const grant = await grantFor(request.channel).catch(() => null);
  // To the player's origin alone, so a grant never reaches another page.
  frame.contentWindow.postMessage({ type: "spine:grant", id: request.id, grant }, PLAYER_ORIGIN);
});

Examples by stack

All of them render the same <iframe>. Only the way you build its URL differs. Keep the player host in your configuration, and build the URL with your language’s URL encoding rather than by gluing strings. In each, the channel is optional: leave it out to play your site’s default channel.

Use the tag from the quick start as it is.

For any page:

// `params` takes `channel` and the player settings. Leave `channel` out for the site's default.
function spineEmbedUrl(host, embedId, params = {}) {
  const url = new URL(`/embed/${encodeURIComponent(embedId)}`, host);
  for (const [name, value] of Object.entries(params)) url.searchParams.set(name, value);
  return url.href;
}

const frame = document.createElement("iframe");
frame.src = spineEmbedUrl("https://player.spinectrl.com", "01jdm8q3vz5k7r2x9c4n6b8t0w", {
  channel: "spor-1",
  latency: "low",
});
frame.title = "Live stream";
frame.allow = "autoplay; fullscreen";
frame.allowFullscreen = true;
frame.style.cssText = "width: 100%; aspect-ratio: 16 / 9; border: 0";
document.getElementById("player-slot").append(frame);

For React and Next.js:

type LivePlayerProps = {
  embedId: string;
  /** The channel's slug or ID. Left out, the site's default channel plays. */
  channel?: string;
  title?: string;
  latency?: "auto" | "low" | "balanced" | "smooth";
};

const PLAYER_HOST = "https://player.spinectrl.com";

export function LivePlayer({ embedId, channel, title = "Live stream", latency }: LivePlayerProps) {
  const src = new URL(`/embed/${encodeURIComponent(embedId)}`, PLAYER_HOST);
  if (channel) src.searchParams.set("channel", channel);
  if (latency) src.searchParams.set("latency", latency);
  return (
    <iframe
      src={src.href}
      title={title}
      allow="autoplay; fullscreen"
      allowFullScreen
      style={{ width: "100%", aspectRatio: "16 / 9", border: 0 }}
    />
  );
}

It has no state or effects, so it works as a Next.js server component as it is.

For Vue and Nuxt:

<script setup lang="ts">
import { computed } from "vue";

// `channel` is the channel's slug or ID. Left out, the site's default channel plays.
const props = defineProps<{ embedId: string; channel?: string; title?: string }>();
const PLAYER_HOST = "https://player.spinectrl.com";

const src = computed(() => {
  const url = new URL(`/embed/${encodeURIComponent(props.embedId)}`, PLAYER_HOST);
  if (props.channel) url.searchParams.set("channel", props.channel);
  return url.href;
});
</script>

<template>
  <iframe
    :src="src"
    :title="title ?? 'Live stream'"
    allow="autoplay; fullscreen"
    allowfullscreen
    style="width: 100%; aspect-ratio: 16 / 9; border: 0"
  />
</template>

Angular blocks a bound src on an iframe unless you mark the URL as trusted. Build it from your own configuration, never from user input:

import { Component, Input, OnChanges, inject } from "@angular/core";
import { DomSanitizer, SafeResourceUrl } from "@angular/platform-browser";

const PLAYER_HOST = "https://player.spinectrl.com";

@Component({
  selector: "app-live-player",
  standalone: true,
  template: `
    <iframe
      [src]="src"
      [title]="title"
      allow="autoplay; fullscreen"
      allowfullscreen
      style="width: 100%; aspect-ratio: 16 / 9; border: 0"
    ></iframe>
  `,
})
export class LivePlayerComponent implements OnChanges {
  @Input({ required: true }) embedId!: string;
  /** The channel's slug or ID. Left out, the site's default channel plays. */
  @Input() channel?: string;
  @Input() title = "Live stream";
  src?: SafeResourceUrl;

  private readonly sanitizer = inject(DomSanitizer);

  ngOnChanges(): void {
    const url = new URL(`/embed/${encodeURIComponent(this.embedId)}`, PLAYER_HOST);
    if (this.channel) url.searchParams.set("channel", this.channel);
    this.src = this.sanitizer.bypassSecurityTrustResourceUrl(url.href);
  }
}
<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;
  export let title = "Live stream";

  const PLAYER_HOST = "https://player.spinectrl.com";

  function embedUrl(embedId: string, channel: string | undefined): string {
    const url = new URL(`/embed/${encodeURIComponent(embedId)}`, PLAYER_HOST);
    if (channel) url.searchParams.set("channel", channel);
    return url.href;
  }

  $: src = embedUrl(embedId, channel);
</script>

<iframe {src} {title} allow="autoplay; fullscreen" allowfullscreen
  style="width: 100%; aspect-ratio: 16 / 9; border: 0"></iframe>

For one page, add a Custom HTML block and paste the tag from the quick start.

To reuse it, register a shortcode in your theme’s functions.php or a small plugin, then write [spine_player channel="spor-1"] in any post, or [spine_player] for your site’s default channel:

<?php
add_shortcode('spine_player', function ($atts) {
    $atts = shortcode_atts([
        'embed'   => '01jdm8q3vz5k7r2x9c4n6b8t0w',
        'channel' => '',
        'title'   => 'Live stream',
    ], $atts, 'spine_player');

    $src = 'https://player.spinectrl.com/embed/' . rawurlencode($atts['embed']);
    if ($atts['channel'] !== '') {
        $src .= '?' . http_build_query(['channel' => $atts['channel']]);
    }

    return sprintf(
        '<iframe src="%s" title="%s" allow="autoplay; fullscreen" allowfullscreen'
        . ' style="width: 100%%; aspect-ratio: 16 / 9; border: 0"></iframe>',
        esc_url($src),
        esc_attr($atts['title'])
    );
});
Server-side templates: PHP, Python, Ruby, Go, Java and C#

Build the URL on the server, then print it into the src attribute with your template engine’s escaping.

<?php
// $params takes 'channel' and the player settings. Leave 'channel' out for the site's default.
function spine_embed_url(string $host, string $embedId, array $params = []): string
{
    $query = http_build_query($params);
    return $host . '/embed/' . rawurlencode($embedId) . ($query === '' ? '' : '?' . $query);
}

$src = spine_embed_url('https://player.spinectrl.com', '01jdm8q3vz5k7r2x9c4n6b8t0w', ['channel' => 'spor-1']);
?>
<iframe src="<?= htmlspecialchars($src, ENT_QUOTES) ?>" title="Live stream"
  allow="autoplay; fullscreen" allowfullscreen
  style="width: 100%; aspect-ratio: 16 / 9; border: 0"></iframe>

For Django, Flask with Jinja, or any template engine that escapes by default:

from urllib.parse import quote, urlencode


# `params` takes `channel` and the player settings. Leave `channel` out for the site's default.
def spine_embed_url(host: str, embed_id: str, **params: str) -> str:
    query = urlencode(params)
    return f"{host}/embed/{quote(embed_id, safe='')}" + (f"?{query}" if query else "")


# In a view:
src = spine_embed_url("https://player.spinectrl.com", "01jdm8q3vz5k7r2x9c4n6b8t0w", channel="spor-1")
<iframe
  src="{{ src }}"
  title="Live stream"
  allow="autoplay; fullscreen"
  allowfullscreen
  style="width: 100%; aspect-ratio: 16 / 9; border: 0"
></iframe>

For Rails:

require "erb"
require "uri"

# `params` takes `channel` and the player settings. Leave `channel` out for the site's default.
def spine_embed_url(host, embed_id, **params)
  query = URI.encode_www_form(params)
  "#{host}/embed/#{ERB::Util.url_encode(embed_id)}#{"?#{query}" unless query.empty?}"
end
<%= tag.iframe src: spine_embed_url("https://player.spinectrl.com", "01jdm8q3vz5k7r2x9c4n6b8t0w", channel: "spor-1"),
               title: "Live stream", allow: "autoplay; fullscreen", allowfullscreen: true,
               style: "width: 100%; aspect-ratio: 16 / 9; border: 0" %>

With html/template, which escapes the attribute for you:

package player

import (
	"net/url"
)

// params takes "channel" and the player settings. Leave "channel" out for the site's default.
func EmbedURL(host, embedID string, params map[string]string) string {
	query := url.Values{}
	for name, value := range params {
		query.Set(name, value)
	}
	embed := host + "/embed/" + url.PathEscape(embedID)
	if len(query) == 0 {
		return embed
	}
	return embed + "?" + query.Encode()
}
<iframe
  src="{{ .PlayerURL }}"
  title="Live stream"
  allow="autoplay; fullscreen"
  allowfullscreen
  style="width: 100%; aspect-ratio: 16 / 9; border: 0"
></iframe>
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

public final class SpineEmbed {
    /** {@code channel} is the channel's slug or ID, or null for the site's default channel. */
    public static String url(String host, String embedId, String channel) {
        String embed = host + "/embed/" + encode(embedId);
        return channel == null ? embed : embed + "?channel=" + encode(channel);
    }

    private static String encode(String value) {
        return URLEncoder.encode(value, StandardCharsets.UTF_8);
    }
}

In Thymeleaf: <iframe th:src="${playerUrl}" title="Live stream" allow="autoplay; fullscreen" allowfullscreen style="width: 100%; aspect-ratio: 16 / 9; border: 0"></iframe>.

For ASP.NET Core, with Razor:

public static class SpineEmbed
{
    // channel is the channel's slug or ID, or null for the site's default channel.
    public static string Url(string host, string embedId, string? channel = null) =>
        $"{host}/embed/{Uri.EscapeDataString(embedId)}"
        + (channel is null ? "" : $"?channel={Uri.EscapeDataString(channel)}");
}
<iframe src="@SpineEmbed.Url("https://player.spinectrl.com", Model.EmbedId, Model.Channel)"
        title="Live stream" allow="autoplay; fullscreen" allowfullscreen
        style="width: 100%; aspect-ratio: 16 / 9; border: 0"></iframe>

Before you launch

  • Register every origin that frames the player. Spine’s host lets only your site’s registered origins frame your embed, and a page anywhere else gets an empty frame. To embed on a new domain, a staging environment or http://localhost, ask Spine to add its origin. A change reaches viewers within about a minute.
  • 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 only https origins, apart from http://localhost for testing.
  • Check your page’s own headers. If your page sends a Content-Security-Policy, allow the player host with frame-src https://player.spinectrl.com. If it sends a Permissions-Policy, it must not take away autoplay or fullscreen: a frame can’t get permissions its page doesn’t have.
  • Test on the devices your audience uses.

More

What the browser says when it refuses the frame

A page on an origin Spine hasn’t registered for your site gets an empty frame, and the browser console says something like:

Refused to frame 'https://player.spinectrl.com/' because an ancestor violates the
following Content Security Policy directive: "frame-ancestors https://www.example.com".

The directive lists the origins that are allowed. See Troubleshooting for what to check.

Remove the player

Remove the <iframe> from the page, or change its src. The player stops its media, timers and requests when its frame goes. In a single-page app, unmounting the component that renders the iframe is enough.

Events and commands

The iframe doesn’t send events to your page, or take commands from it: on a site with customer grants it asks for grants, and that’s all. If you need to know whether the player is playing, off air or refused, or want your page to switch channel or open picture-in-picture, use the hosted script, whose element fires spine-state and takes commands.