Serving media
The media route
GET <baseUrl>/media/<externalId>?t=<mediaToken>
The Stage resolves this address when a song is about to play, from what you most recently synced, and keeps it for the length of that song.
| Part | Rule |
|---|---|
baseUrl |
Only the origin is used: scheme, host, and port. A path is discarded, so the route is always /media/… at the root of that origin, never /music/media/… because that is where you mounted it. |
externalId |
Percent-encoded into the last path segment. Decode it. An id with a space or a slash in it arrives as %20 or %2F. A track’s loopId goes in the same place. See Looping covers. |
t |
Your media token. |
preview=1 |
Added for a preview. See Answering on demand. |
Serve a certificate the Stage’s browser already trusts. The Stage is a web page and has nobody to click through a warning, so a self-signed certificate does not work however it is installed. On a home network, use the name and certificate described in A name and a certificate.
Answer a media request
| Request | Answer |
|---|---|
No Range header |
200 with the whole file. |
Range: bytes=N- or bytes=N-M |
206, a Content-Range, and a Content-Length of the part and not the whole. |
Range starting past the end |
416 with Content-Range: bytes */<size>. |
OPTIONS |
204 with the CORS headers. |
| Wrong or missing token | 403. |
Unknown externalId or loopId |
404. |
Range requests are required. Media elements seek with them; a server that ignores Range typically plays once and then breaks the moment anyone scrubs.
Send Accept-Ranges: bytes on every response.
Send Access-Control-Allow-Private-Network: true if you are on a private address.
Send the right Content-Type for the container.
| Container | Content-Type |
|---|---|
| MP4 | video/mp4 |
| WebM | video/webm |
| MOV | video/quicktime |
| MP3 | audio/mpeg |
| M4A | audio/mp4 |
CORS
Required if you declare canAnalyzeAudio, and recommended whether or not you do. Without that capability the Stage uses a plain <video> or <audio> element, which plays cross-origin media without CORS headers; declaring it makes the Stage ask in a mode that fails outright without them. See Capabilities.
Send them on every successful response to a media address — 200, 206, and 416 alike. They need not be on a 403 or a 404.
| Header | Value |
|---|---|
Access-Control-Allow-Origin |
The origin that asked, taken from the Origin header, or *. The Stage sends no credentials, so a wildcard is acceptable. |
Vary |
Origin — required only if you echo the origin. |
Access-Control-Expose-Headers |
Content-Length, Content-Range |
Access-Control-Allow-Methods |
GET, HEAD, OPTIONS — on the OPTIONS answer. |
Access-Control-Allow-Headers |
Range — on the OPTIONS answer. |
If the address redirects, every hop has to do the same.
The media token
You generate the media token. We store it, encrypted, and put it in the address the Stage is given, which is how the Stage proves to you that the screen is allowed to ask.
Rotating it is fine, on every restart if you like, because the next sync tells us the new one. A Stage already holding an address for the song that is playing gets a 403 on its next range request, so a restart interrupts what is on the screen, and so does a song that begins before the first sync after the restart has landed. Send that sync as early as you can. Songs resolved after it play.
When playback fails
| Situation | What the room sees |
|---|---|
| No address, because the library was deleted or has never synced | The Stage says the library holding the song is not reachable, and waits. It does not skip. |
| An address the browser cannot load | The Stage skips the song and moves on to the next one, with nothing on the screen to say why. |
| A looping cover the browser cannot load | The song plays, with the track’s artwork. |
Answer a wrong token with a plain 403 and nothing else, so your own logs can tell the cases apart.
Formats
The Stage plays through a browser media element, so what plays is what the browser opens. A container is only half of it; the codec inside is the other half.
| Container | Codecs | Plays |
|---|---|---|
| MP4, MOV | H.264 video, AAC audio | Everywhere |
| MP4, MOV | HEVC (H.265) | Some devices and not others. A .mov from a camera or an editor is often one of those. |
| WebM | VP8 or VP9 video, Vorbis or Opus audio | Yes |
| MP3 | — | Everywhere |
| M4A | AAC | Everywhere |
| M4A | Apple Lossless | Not every browser |
| MKV, AVI, WMV, FLV | — | Never |
| CDG+MP3 | — | Never |
Nothing in the service looks inside a file. The bridge decides by extension alone, so an .mp4 it reports as playable can still refuse on a particular television. Whether a file is playable is yours to decide.
Mark anything the browser will not open with playable: false, per track. Transcode when you can.
A track marked that way is still cataloged, and its owner still sees it on the library page marked as one that will not play. It is kept out of browse and search, so nobody can queue it.
Omitting the flag means playable.
Serve a looping cover
A cover named by a track’s loopId is fetched exactly as a song is:
GET <baseUrl>/media/<loopId>?t=<mediaToken>
There is no other route and no parameter to add. The token, range requests, CORS and 404 all work as they do above, so answer a loopId wherever you answer an externalId.
video/mp4orvideo/webm, sent as theContent-Type, with the codecs Formats says play everywhere. A GIF will not play.- A few seconds, and small. It loops, and the Stage mutes it.
The field that names it is described in Add a looping cover.