Platforms
The platform is auto-detected from the shape of src - there's no prop to set.
| Platform | Type | URL format |
|---|---|---|
| YouTube | Embed | https://www.youtube.com/watch?v=VIDEO_ID · youtu.be/... |
| Vimeo | Embed | https://vimeo.com/VIDEO_ID |
| Dailymotion | Embed | https://www.dailymotion.com/video/VIDEO_ID · dai.ly/... |
| Brightcove | Source | https://players.brightcove.net/ACCOUNT_ID/PLAYER_ID/index.html?videoId=VIDEO_ID |
| JW Player | Source | https://cdn.jwplayer.com/videos/... · jwplayer://MEDIA_ID |
| MP4 | Native | Direct file URL |
| HLS | Native | Direct .m3u8 URL - hls.js, or Safari's native HLS |
| DASH | Native | Direct .mpd URL - dash.js |
Anything unmatched falls back to native <video>.
Embed vs. source vs. native
Which of the three a URL falls into decides which features it gets:
- Embed (YouTube, Vimeo, Dailymotion) - plays through the platform's own iframe SDK, its events translated into the player's common set. The
<video>element exists only to mask iframe loading chrome. With no real<video>in play, captions, quality, and PiP come from the platform, not the player - Vimeo's caption tracks are the exception, listed in the player's captions menu while Vimeo still draws them - and ads aren't supported. - Source (Brightcove, JW Player) - the platform hosts a file behind an opaque URL. The player resolves it to a real
<video>/HLSsrc, so captions, quality, PiP, and ads all work exactly as for a direct file. Caption files the platform lists beside the stream (Brightcove'stext_tracks, JW Player'stracks) are added as tracks too, unless the player was giventracksof its own. Brightcove also auto-discovers its own ad tag. - Native (MP4/HLS/DASH) - hls.js, dash.js, or Safari's native HLS drive a real
<video>. HLS and DASH expose adaptive quality levels, and HLS subtitle renditions come straight from the manifest.
Each platform's adapter is loaded on demand, so a page that only plays MP4 downloads none of the embed SDKs.
Adding or overriding a platform
registerPlatform teaches the player a URL shape it doesn't know, without forking. A registration is tried before the built-ins, so a matcher for a URL YouTube or Brightcove already claims takes it over.
import { registerPlatform } from '@munsonlabs/video-player'
// A source resolver: turn a URL into something the native player can load.
registerPlatform({
key: 'acme',
test: (src) => src.startsWith('acme://'),
embed: false,
resolveSource: async (src) => {
const { url, poster } = await fetch(`/api/acme/${src.slice(7)}`).then((r) => r.json())
return { src: url, type: 'application/x-mpegURL', poster }
},
})
Set embed: true and supply createAdapter instead when the platform has its own iframe SDK; that adapter implements PlaybackAdapter, whose captions, quality and Picture-in-Picture capabilities are optional - omit what the SDK can't do.
resolvePlatform(url) reports what a URL would resolve to, which is useful for asserting a registration took effect.
registerPlatform has to run before the player mounts. With the custom elements that means registering before the tag upgrades, since customElements.define() upgrades matching tags already in the DOM synchronously.