Skip to main content

useTextTracks()

useTextTracks(): TextTrack[]

Returns the list of available text tracks (subtitles or captions) for the current media.

This hook provides a reactive way to observe and respond to changes in the player’s text track model. Each track typically represents a subtitle, caption, or timed text stream — for example, different languages or accessibility captions.

⚠️ Must be used within a PlayerProvider or AVPlayerViewControllerProvider component.

Returns

TextTrack[]

{TextTrack[]} An array of available TextTrack for the current media.

Example

import React from 'react';
import { View, Text, Button } from 'react-native';
import { usePlayer, useTextTracks } from '@castlabs/react-native-prestoplay';

export default function SubtitleSelector() {
const player = usePlayer();
const tracks = useTextTracks();
const activeTrack = tracks.find(t => t.active);

const selectTrack = async (track: TextTrack | null) => {
// If track is null, subtitles are hidden.
await player.getTrackManager().setTextTrack(track);
};

return (
<View>
<Text>Subtitles</Text>
<Button
title={`Off${!activeTrack ? ' ✓' : ''}`}
onPress={() => selectTrack(null)}
/>
{tracks.map(t => (
<Button
key={t.id}
title={`${t.language || 'Unknown'}${t.active ? ' ✓' : ''}`}
onPress={() => selectTrack(t)}
/>
))}
</View>
);
}