Skip to Content
📧 Join the Teacharium waitlist to get access. 

Media Resolution

Lessons may reference media files (images, videos, voiceovers) by ID. You provide resolver hooks that map these IDs to actual URLs.

import { TeachariumPlayer } from "@teacharium/player"; import { getWidgets } from "@teacharium/widget"; // Map media IDs to static file paths const mediaFiles: Record<string, string> = { "media:abc123": "/lessons/my-lesson/images/intro.png", "media:def456": "/lessons/my-lesson/images/diagram.jpg", }; // Hook that resolves media IDs to URLs function useMediaUrl(mediaId: string | undefined) { if (!mediaId) { return { data: null, isLoading: false, error: null }; } return { data: mediaFiles[mediaId] ?? null, isLoading: false, error: null }; } // Hook that resolves a voiceover to its audio URL. Voiceovers are looked up // by the script's hash, the voice and the speed the audio was generated at. // Lesson exports list every clip in manifest.json under files.voiceovers. function useVoiceoverUrl( contentHash: string | undefined, voice: string | undefined, speed?: number, ) { if (!contentHash || !voice) { return { data: null, isLoading: false, error: null }; } return { data: `/lessons/my-lesson/voiceovers/${contentHash}_${voice}_${speed ?? 1}.mp3`, isLoading: false, error: null, }; } function LessonPage() { return ( <TeachariumPlayer lesson={lessonData} widgets={getWidgets()} mediaResolvers={{ useMediaUrl, useVoiceoverUrl, }} /> ); }

If you have the export’s manifest.json, createVoiceoverMapResolver from @teacharium/player builds this hook for you from a map keyed with voiceoverKey(contentHash, voice, speed); see the sample app.

Sized image references

An image reference can ask for a display width: media:abc123?w=960. Teacharium serves those as resized copies at the next standard width up (200, 400, 960 or 1440 px). Your useMediaUrl receives the whole value, so either map each sized reference to its own file (lesson exports package them as ./media/{uuid}-w{width}.webp) or drop everything from ? onward to fall back to the original.

Resolver Hook Interface

The resolver hooks must return this shape:

interface MediaUrlResult { data: string | null | undefined; isLoading?: boolean; error?: Error | null; }