Skip to main content

useAudioTracks()

useAudioTracks(): AudioTrack[]

Returns the list of available audio tracks for the current media.

This hook provides a reactive way to observe and respond to changes in the player’s audio track model. Each track represents an available audio stream (for example, different languages, commentary, or alternative mixes).

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

Returns

AudioTrack[]

AudioTrack[] An array of available AudioTrack for the current media.

Example

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

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

const selectTrack = (id: string) => {
const track = tracks.find(t => t.id === id);
if (track) player.getTrackManager().setAudioTrack(track);
};

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