Thumbnails¶
The thumbnails plugin displays seek-bar preview images so viewers can navigate content visually. It supports thumbnail tracks embedded in a stream and side-loaded ones. It’s a plugin, so you install and enable it separately.
Review Thumbnails first for shared thumbnail formats, manifest signaling, and authoring patterns.
Setup¶
First, install the @castlabs/react-native-prestoplay-thumbnails package:
npm install @castlabs/react-native-prestoplay-thumbnails
Once the plugin is installed, enable it when initializing the SDK, by passing the ThumbnailPlugin class. For example:
import { Sdk } from "@castlabs/react-native-prestoplay";
import { ThumbnailPlugin } from "@castlabs/react-native-prestoplay-thumbnails";
Sdk.initialize({
licenseKey: {
/* Valid license here */
},
plugins: [ThumbnailPlugin],
});
Usage¶
If a thumbnail track is not embedded in a stream, side-loading of a thumbnail track is available.
When initializing the player, specify a remote thumbnail track in the player configuration. For example:
<PlayerProvider
playerConfig={{
autoPlay: true,
source: {
/* ... */
},
remoteThumbnailTracks: [
{
url: "https://example.com/thumbs/$index$.jpg",
mimeType: "image/jpeg",
gridHeight: 1,
gridWidth: 1,
intervalMs: 10000,
},
],
}}
/>
Note
On iOS and tvOS, a sideloaded track is not required when the stream itself carries an I-frame only track (an HLS EXT-X-I-FRAME-STREAM-INF rendition): those frames are rendered by the Apple thumbnails engine. When remoteThumbnailTracks is configured, the sideloaded track takes precedence.
With the plugin enabled, use the Thumbnail component to display a single thumbnail at a specific time in the video:
// positionMs: time in milliseconds where the thumbnail should appear
// style: adjust the size of the thumbnail
<Thumbnail positionMs={positionMs} style={{ width: 150, height: 100 }} />
Place the Thumbnail component inside the PlayerProvider so it has access to the player instance.
Error handling¶
On Android and web, the Thumbnails plugin emits ErrorCode.ThumbnailsImageMissing when a thumbnail image cannot be loaded. Subscribe to player errors to handle this case:
import {
ErrorCode,
ErrorDetails,
EventType,
} from "@castlabs/react-native-prestoplay";
player.addEventListener(EventType.Error, (event) => {
const { error } = event.details as ErrorDetails;
if (error.code === ErrorCode.ThumbnailsImageMissing) {
// Thumbnail image unavailable — hide the thumbnail UI or show a placeholder
}
});
This error is non-fatal and doesn’t affect playback.
On iOS and tvOS the Apple engine raises the same error when it cannot produce a frame for a requested position — including positions requested before the I-frame track is ready, and every position of a stream that carries no I-frame track at all. Scrubbing such content can therefore raise ThumbnailsImageMissing repeatedly, so treat it as “no thumbnail for now” rather than a fatal condition.