Hooks

Settings Hooks

useSettings()

A hook for managing video settings such as videoTrack, audio tracks, and subtitle tracks, and controlling the visibility of a settings menu.

Usage

import { useSettings } from 'react-native-video-toolkit';

export const MyComponent = () => {
  const { isSettingsMenuVisible, toggleSettingsMenu } = useSettings();
  // ...
};

Returns

ValueTypeDescription
videoTrackVideoTrack | nullThe current video quality setting.
videoTracksVideoTrack[]The list of available video qualities.
setVideoTrack(newVideoTrack: VideoTrack | null) => voidA function to set the video quality.
getVideoTracks(videoTracks: VideoTrack[]) => voidA function to get the available video qualities.
audioTrackAudioTrack | nullThe current audio track setting.
audioTracksAudioTrack[]The list of available audio tracks.
setAudioTrack(newAudioTrack: AudioTrack | null) => voidA function to set the audio track.
getAudioTracks(audioTracks: AudioTrack[]) => voidA function to get the available audio tracks.
textTrackTextTrack | nullThe current subtitle track setting.
textTracksTextTrack[]The list of available subtitle tracks.
setTextTrack(newTextTrack: TextTrack | null) => voidA function to set the subtitle track.
getTextTracks(textTracks: TextTrack[]) => voidA function to get the available subtitle tracks.
isSettingsMenuVisiblebooleanA boolean indicating whether the settings menu is currently visible.
openSettings() => voidA function to explicitly open the settings menu.
closeSettings() => voidA function to explicitly close the settings menu.
toggleSettingsMenu() => voidA function to toggle the visibility of the settings menu.

Example

import { useSettings, VideoPlayer } from 'react-native-video-toolkit';
import { GestureDetector } from 'react-native-gesture-handler';
import React from 'react';
import { View, Button } from 'react-native';

const MySettingsButton = () => {
  const { openSettings } = useSettings();

  const handleQualityChange = () => {
    // Example: set quality to the first available track
    if (videoTracks.length > 0) {
      setVideoTrack(videoTracks[0]);
    }
  };

  return <BaseIconButton IconComponent={SettingsIcon} onTap={openSettings} />;
};

export default MySettingsButton;