Published
What a lesson page needs
- A video that only your signed-in learners can watch.
- A player with captions, speed and quality menus.
- A way to record that the learner finished.
Store the video's ID against each lesson. The rest is a signed URL from your server and a player on the page. To list lessons as a grid of posters, see Build a video library page.
1. Keep the videos private
Turn on signed reads for the app: Settings, Read access in the dashboard, or await fileboy.setRequireSignedReads(true). Reads then need a signature that only your server, with your private key, can make. The signed URLs docs cover what that includes. This is access control by URL: there is no DRM, so a learner who can watch a video can also record it.
On the server, sign each video for the length of a viewing, only for learners who are enrolled:
import { Fileboy } from "@cd2/fileboy-node"
const fileboy = Fileboy({
publicKey: process.env.FILEBOY_PUBLIC_KEY!,
privateKey: process.env.FILEBOY_PRIVATE_KEY!,
})
export async function lessonForLearner(userId: string, lessonId: string) {
const lesson = await db.lessons.get(lessonId) // { title, videoId, ... }
if (!(await db.enrolments.has(userId, lesson.courseId))) {
throw new Error("Not enrolled")
}
return {
title: lesson.title,
videoId: lesson.videoId,
// lasts 4 hours: make it as long as a viewing takes
signedQuery: fileboy.signVideo(lesson.videoId, { expiresIn: 4 * 3600 }),
}
}2. Play it and record progress
Give the player the video's ID and the signed query. It fires timeupdate and ended with { currentTime, duration } in event.detail.
import { useEffect, useRef } from "react"
import "@cd2/fileboy-player"
export function Lesson(props: { lessonId: string; videoId: string; signedQuery: string }) {
const ref = useRef<HTMLElement>(null)
useEffect(() => {
const player = ref.current
if (!player) return
let lastSaved = 0
const onTime = (e: Event) => {
const { currentTime } = (e as CustomEvent).detail
// save the position every 15 seconds, to resume later
if (currentTime - lastSaved >= 15) {
lastSaved = currentTime
fetch(`/api/lessons/${props.lessonId}/position`, {
method: "POST",
body: JSON.stringify({ seconds: Math.floor(currentTime) }),
})
}
}
const onEnded = () => fetch(`/api/lessons/${props.lessonId}/complete`, { method: "POST" })
player.addEventListener("timeupdate", onTime)
player.addEventListener("ended", onEnded)
return () => {
player.removeEventListener("timeupdate", onTime)
player.removeEventListener("ended", onEnded)
}
}, [props.lessonId])
return <fileboy-player ref={ref} video-id={props.videoId} signed-query={props.signedQuery} />
}The browser tells your server a lesson is finished, so a learner can say so without watching. For a certificate or a gate, treat it as a hint. For real watching figures, see video analytics.
3. Captions and what comes next
Captions uploaded for the video, or made automatically when you have turned that on, appear in the player's captions menu with no extra code. See captions for adding them yourself.
Checked against the current libraries in November 2026. Found something that no longer works? Tell us.