Skip to content

Add Player behavior

A plugin’s Player behavior has two halves: the server projects Player state for each screen, and the plugin’s Player code reacts to that state. Drawing on screen is optional. A plugin that plays background audio, watches what’s on screen, or drives hardware is just as much a Player plugin as one that shows a ticker.

The shared Player Runtime runs the same runtime/index.ts on Tilecast Edge, Windows, Android, and the Browser Player. Each Player reports what it supports, so your plugin never checks which platform it’s on. See the Player Runtime contract for the host boundary.

This page covers the Player part of Plugin API v2, which Plugin Manifest API 3 keeps. Countdown Bar and the Emergency Alerts ticker are the shipped examples. Plugin API v1 surfaces are retired.

Implement plugin.PlayerStateProjector on the server. Each value has a stable ID, a state type and version from the manifest’s player.state, a small JSON object, any media variants it uses, and an optional expiry.

func (p *Plugin) ProjectPlayerState(ctx context.Context, screen uuid.UUID) ([]plugin.PlayerState, error) {
return []plugin.PlayerState{{
ID: notice.ID, Type: "transit_alert", Version: 1,
State: map[string]any{"text": notice.Text},
}}, nil
}

When the data changes, use Host.Manifests to revise the affected screens, the same way as any other plugin. A state change reaches the Player without restarting the playlist, video, or Layout on screen.

Players that don’t host Plugin API v2 never receive the state. To keep those Players working, list the entry types they understand in player.v1ManifestTypes and also return those entries: those Players then get the old entries, and the host hands them to your code as state, so one implementation serves every Player. Countdown Bar and Emergency Alerts work this way.

runtime/index.ts default-exports definePlayerPlugin(...) and lists the same services as the manifest.

import { definePlayerPlugin } from "@tilecast/plugin-sdk/player";
export default definePlayerPlugin({
id: "transit_alerts",
services: {
required: ["player.clock@1", "player.surface@1"],
optional: ["player.presentation.observe@1"],
},
activate(context) {
const clock = context.services["player.clock@1"];
const observe = context.services["player.presentation.observe@1"]; // may be null
return {
stateChanged(entries) {
/* react to this plugin's current state */
},
dispose() {
/* release anything you created */
},
};
},
});

The host activates the plugin when its first state arrives and disposes it when the state goes away. Every hook is optional, so implement only the ones you use: stateChanged, awakeChanged, servicesChanged, describe, and dispose.

There’s no evaluation loop. If something should happen later, schedule it with the clock service’s after or every. Timers stop automatically when the plugin is disposed.

If your code throws, the host disposes your plugin and keeps everything else running.

Service Use it for
player.clock@1 Corrected server time and timers.
player.events@1 Events between your native part and your Shared Runtime part.
player.fonts@1 Organization font families your state declares. Anything else returns null.
player.media@1 Addresses for media your state declares. Anything else returns null.
player.presentation.observe@1 What’s on screen: the current item, its kind, and whether it may play sound.
player.presentation.provide@1 A provider that supplies presentation behavior when the host asks for it.
player.surface@1 Strips, corners, and overlays, with push or overlay geometry.

Ask only for what you use. A missing required service means the Player won’t run your plugin; a missing optional service is null, and servicesChanged tells you if it appears later.

Declare each visual contribution in player.runtime.surfaces with its slots and tier, then open it:

const ticker = context.services["player.surface@1"].open("ticker", (grant) => {
element.hidden = !grant.shown.has("strip.bottom");
});
ticker?.claim([
{ slot: "strip.bottom", priority: 10, heightPx: 64, displayMode: "push" },
]);

The host gives you a container for each slot and keeps it mounted, so media isn’t decoded again and animations don’t restart. The tier comes from the manifest, so a claim can’t outrank a stronger tier: Emergency Alerts still wins the bottom strip over everything at a weaker tier. For fullscreen content, use a Takeover rather than an overlay.

State is for things the server decides. An event is for something that happens on the screen’s own hardware and doesn’t belong in state: a button press, a request to skip, a chime. Events connect the native part and the Shared Runtime part of one plugin.

Declare each event in player.events, then use the service:

const events = context.services["player.events@1"];
const stop = events.on("button_pressed", 1, (payload) => {
/* react to the press */
});
events.emit("ring_chime", 1, { times: 2 });

Events are small and short-lived:

  • The payload is a plain JSON object of at most 2 KiB.
  • Delivery is at most once. There’s no retry and no replay, so keep anything that must survive in state.
  • An event reaches only your own plugin, and only the events you declared.
  • When your plugin is disposed, it can no longer send or receive events.

An event can’t call a function in the other part, and it can’t carry configuration.

No Player carries events between its host and the Runtime yet, so player.events@1 isn’t available on any Player today. Request it as optional if your plugin can run without it. The Plugin API v2 reference says where delivery stops.

A plugin that brings its own way of showing content, such as a live video source or a screen-mirroring receiver, declares a provider and offers it with player.presentation.provide@1:

context.services["player.presentation.provide@1"].provide("receiver", {
start(session) {
session.container.append(video);
session.presenting(); // first frame is on screen
return { stop: () => video.remove() };
},
});

The Player decides when your provider runs. It starts only when an external presentation names <your plugin id>/receiver. The Player gives you a container, shows it while you hold the screen, and stops you when the presentation changes. If your provider throws or calls session.fail(reason), the Player shows its own screen and reports the error.

Your provider doesn’t control playback, and it can’t take over the Player.

Hardware features such as a GPIO input or a sensor need native code. A native contribution is a Rust crate in plugins/<name>/native/<id>/ that Tilecast compiles into the Player. Tilecast never loads native code at run time, and third-party native code isn’t supported.

The crate asks for native services, typed Rust interfaces the platform provides. A Player that lacks a required native service leaves the contribution off. No Player provides a native service yet, so this page doesn’t list any. See the Plugin API v2 reference before you add one.

Put runtime styles in runtime/*.css. Every selector starts with the plugin scope, such as .tc-transit-alerts. Keyframe names use the same prefix.

plugins:check rejects styles that could reach another plugin or the Player itself.