Video Piper APIv1 Home OpenAPI spec

Docs › The <video-piper> web component

The <video-piper> web component

A drop-in player that plays the stream (HLS, with hls.js loaded only where the browser needs it) or the MP4, shows captions, and refreshes its links before they expire. One script, no framework, about 3 KB gzipped:

Install: each component is one script tag from this site, or, with a bundler, npm install @videopiper/elements and import "@videopiper/elements/player" (also /recorder, /editor, /thumbnail; TypeScript types included). The same scripts are on jsDelivr: https://cdn.jsdelivr.net/npm/@videopiper/elements@0/dist/cdn/recorder.js. Runnable examples: github.com/Video-Piper/demos.

<script src="https://videopiper.com/player/player.js"></script>

<video-piper links-url="/api/videos/VIDEO_ID/links"></video-piper>

links-url is your own endpoint, like the server example above: it returns JSON with playbackUrl, streamUrl, posterPlaybackUrl (or posterUrl), captionsUrl, captionsStatus (the status's captions.status) and playbackExpiresAt. The player calls it again a few minutes before the links expire (and after a playback error), keeping the viewer's place. To render the first links on the page yourself, pass them as attributes too:

<video-piper src="PLAYBACK_URL" stream-src="STREAM_URL" poster="POSTER_PLAYBACK_URL"
             captions="VTT_URL" expires-at="1790910405" links-url="/api/videos/VIDEO_ID/links"
             cc start="30"></video-piper>
AttributeDescription
srcThe MP4 (playbackUrl). Used where there's no stream or HLS can't play.
stream-srcThe HLS stream (streamUrl, Pro and Scale). Preferred when present.
posterThe poster image (posterPlaybackUrl).
captions, captions-lang, captions-labelA WebVTT file for the MP4 (the stream carries its own subtitle track).
chaptersThe video's chaptersUrl (or chaptersUrl in your links-url answer): marks on the seek bar and a chapter menu. element.chapters lists them ({start, end, title}) and seekToChapter(i) jumps to one.
captions-statusprocessing when the captions aren't made yet; see see the notes below on captions that finish later.
expires-atUnix time the links expire (playbackExpiresAt); when to refresh.
links-urlYour endpoint for fresh links (JSON, same names as the status).
autoplay, muted, loopAs for <video>; autoplay also mutes, as browsers require.
ccShow captions from the start.
startStart at this many seconds.
controlsBy default the player draws its own controls, the same in every browser: play, a seek bar with chapter marks (hover for the time and chapter), the time and current chapter (which opens the chapter menu), volume, captions, speed and full screen. They hide while playing and come back when the pointer moves. Keys, once the player has focus: Space or K play/pause, ←/→ 5 s, J/L 10 s, Shift+←/→ previous/next chapter, ↑/↓ volume, M mute, F full screen, C captions, 0–9 jump to 0–90%. controls="native" uses the browser's own controls instead (chapters then appear as a menu over the video); controls="false" shows none. Style the bar from your page with video-piper::part(controls).
  • No token or key in the page. The signed links are the only thing the player needs. Your API key stays on your server, and you decide who your links-url endpoint answers (for example, only signed-in users; the player sends your site's cookies with it). Embedding doesn't need to be turned on: that switch is only for the iframe embed below.
  • No endpoint? Leave out links-url and listen for the vp-expiring event, then call element.setLinks({playbackUrl, streamUrl, posterPlaybackUrl, captionsUrl, playbackExpiresAt}) with fresh links.
  • Captions that finish later. Captions are made after the video is published, so for the first minutes your links-url may answer with captionsStatus: "processing" (and no captionsUrl; send s.captions?.status and s.captions?.vttUrl from the video's status). The player then asks links-url again about every 20 seconds, easing to 45, only while the tab is visible and for at most 10 minutes. When captionsUrl appears it adds the subtitles track to the playing video without reloading or interrupting it (shown at once only with cc), the CC control appears, and the element fires a bubbling vp-captionsready event with detail: { url, language }, once. If the captions are skipped or failed it simply stops asking. Without links-url it doesn't check; call setLinks() when you learn the captions are ready.
  • Events (they bubble out of the player): vp-loaded, vp-play, vp-pause, vp-ended, vp-seeked, vp-timeupdate (about 4 a second while playing), vp-volumechange and vp-ratechange, each with {currentTime, duration, paused, muted}, and vp-error ({message, code}: NO_VIDEO, EXPIRED, or LOAD_RETRYING while it tries again), plus vp-captionsready and vp-expiring above, and vp-chapterchange ({index, start, end, title}) as playback enters another chapter.
  • Control it like a <video>: play(), pause(), and currentTime (set it to seek), duration, paused, ended, muted, volume, playbackRate.
  • Callbacks: every event also has an on… property that gets its detail: onLoaded, onPlay, onPause, onEnded, onSeeked, onTimeUpdate, onVolumeChange, onRateChange, onError, onCaptionsReady, onExpiring.
    const player = document.querySelector("video-piper");
    player.onEnded = () => showNextVideo();
    player.onTimeUpdate = ({ currentTime, duration }) => track(currentTime / duration);
    player.currentTime = 30; player.play();
  • Sizing: it's 16:9 by default; style it like any element (video-piper { width: 100%; }).
  • Try every option live. In the app, Account → Playground (sign in) lets you set up the player, run your page in an isolated frame with a stand-in for your server, see its events and errors, and copy the page and server code.
  • Your allowed domains apply as usual: the links only play on your sites.