Player for talking to it.
JavaScript example on GitHub
Vite and TypeScript, with custom controls and an event log.
bun install && bun dev plays a demo video.Quickstart
1
Install player.js
tsconfig.json includes, for example player.js.d.ts. It covers the methods and events the Bunny Player supports:player.js.d.ts
2
Create the player function
The
Player has to exist before the iframe finishes loading. Creating both in one function takes care of the order.src/bunny-player.ts
3
Mount it
src/main.ts
params takes any player parameter.Control playback
send() covers the gap:
play() before the viewer has clicked anything. Mute first if playback has to start on its own. The Playback control API lists every method and event.
Track progress
timeupdate fires several times a second. Throttle it before it reaches your backend.
params: { t: savedSeconds } to resume.
Use it without a bundler
We host a build of player.js that addssetPlaybackRate() and the playbackratechange event (Methods). Classic scripts run as the browser parses them, which puts both scripts ahead of the iframe’s load.
Troubleshooting
The ready event never fires
The ready event never fires
The iframe loaded before player.js was listening. Module and
defer scripts run after parsing, by which time an iframe in the HTML may be done. Create the iframe from script, as createBunnyPlayer does.A hidden tab also holds ready back until the viewer switches to it.Events fire twice after replacing the video
Events fire twice after replacing the video
Each
Player leaves a message listener on window for good. Guard its handlers with a flag and flip it when you remove the iframe.The iframe shows a 403
The iframe shows a 403
The library’s allowed domains, direct access block, or token authentication is rejecting the embed. See Embedding restrictions.