Thumbnails
**********
Thumbnails plugin ("ThumbnailPlugin"). Displays seek-bar preview
images from embedded or side-loaded thumbnail tracks. Install and
enable 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"
(https://players.castlabs.com/react-native/1.4.2/docs/thumbnails-plugin-api/classes/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"
(https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/PlayerConfiguration/#remotethumbnailtracks)
in the player configuration. For example:
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"
(https://players.castlabs.com/react-native/1.4.2/docs/thumbnails-plugin-api/variables/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
Place the "Thumbnail"
(https://players.castlabs.com/react-native/1.4.2/docs/thumbnails-plugin-api/variables/Thumbnail/)
component inside the "PlayerProvider"
(https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/variables/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.