Subtitles ********* Subtitles plugin ("SubtitlesPlugin"). Renders embedded and side-loaded text tracks. Install and enable separately. Setup ===== First, install the "@castlabs/react-native-prestoplay-subtitles" package: npm install @castlabs/react-native-prestoplay-subtitles Once the plugin is installed, enable it when initializing the SDK, by passing the "SubtitlesPlugin" (https://players.castlabs.com/react-native/1.4.2/docs/subtitles-plugin-api/classes/SubtitlesPlugin/) class. For example: import { Sdk } from "@castlabs/react-native-prestoplay"; import { SubtitlesPlugin } from "@castlabs/react-native-prestoplay-subtitles"; Sdk.initialize({ licenseKey: { /* Valid license here */ }, plugins: [SubtitlesPlugin], }); Showing subtitles ================= Text tracks embedded in a stream are automatically accessible through the "Player.getTrackManager" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/classes/Player/#gettrackmanager) method. The "TrackManager" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/classes/TrackManager/) provides utilities to manage subtitle tracks, such as selecting or disabling tracks. To display subtitles, select a specific text track using the "TrackManager.setTextTrack" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/classes/TrackManager/#settexttrack) method. For example: const selectedTextTrack = player .getTrackManager() .getTextTracks() .find((t) => t.language === "en"); if (selectedTextTrack) { trackManager.setTextTrack(selectedTextTrack); } Hiding subtitles ================ To hide the subtitles overlay, use the "TrackManager.setTextTrack" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/classes/TrackManager/#settexttrack) method with "null" as the argument. For example: player.getTrackManager().setTextTrack(null); Adding side-loaded subtitles ============================ If a stream lacks embedded subtitles or additional subtitles need to be added, side-loaded subtitles can be defined through the "PlayerConfiguration.remoteTextTracks" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/PlayerConfiguration/#remotetexttracks) configuration. This allows specifying subtitles that are loaded from external URLs. const playerConfiguration = { source: { /* ... */ }, remoteTextTracks: [ { language: "en", label: "English", url: "https://example.com/en.vtt", mimeType: "text/vtt", }, ], }; Styling subtitles ================= Override the subtitle style defined in the content by providing a custom style: const subtitlesExtension = useSubtitlesExtension(); subtitlesExtension.setStyle({ autoFlow: true, fontScale: 1.5, foregroundColor: { // white red: 255, green: 255, blue: 255, alpha: 1, }, backgroundColor: { // black red: 0, green: 0, blue: 0, alpha: 1, }, }); Or use the system's default subtitle style: const subtitlesExtension = useSubtitlesExtension(); subtitlesExtension.setStyle({ extendSystemStyle: true, }); Supported formats ================= For a full list of supported subtitle formats, refer to the Features page.