Skip to content
FrameworkStyle

AudioTrackRadioGroup

A menu radio group for selecting an audio track

Creates radio items from the player audio track state and selects the enabled track.

Import

import { AudioTrackRadioGroup } from '@videojs/react/ui/audio-track-radio-group';

Anatomy

<AudioTrackRadioGroup.Root>
  <Menu.Trigger>
    <AudioTrackRadioGroup.Value />
  </Menu.Trigger>
  <Menu.Content>
    <AudioTrackRadioGroup.Options
      renderItem={(props, item) => (
        <Menu.RadioItem {...props}>
          {item.label}
          <Menu.ItemIndicator checked={item.checked} />
        </Menu.RadioItem>
      )}
    />
  </Menu.Content>
</AudioTrackRadioGroup.Root>

Behavior

The group is available when the configured media exposes more than one audio track. Labels use the track label, then language, then kind. Pass formatTrack to customize the visible labels.

AudioTrackRadioGroup.Root uses useAudioTrackOptions to own selection and renders no element. Wrap the menu’s Menu.Trigger and Menu.Content in it so the trigger inherits the group’s disabled and hidden state and exposes data-availability. AudioTrackRadioGroup.Options renders the items: its required renderItem callback renders the Menu.RadioItem root and receives item state containing the translated label and current checked value. AudioTrackRadioGroup.Value displays the selected label, typically inside the trigger. Options and Value render null when the audio track feature is not configured.

The AudioTrackRadioGroup export from the @videojs/react root is a compatibility component that composes Root and Options behind the former single-component props. Prefer the parts for new code.

Styling

Attribute Values Description
data-audio-track string Current audio track value.
data-disabled Present / absent Present when audio track selection is disabled.
data-hidden Present / absent Present when multiple audio tracks are unavailable.
data-availability "available" / "unavailable" Whether multiple audio tracks are available.

Unavailable groups receive the native hidden attribute.

Accessibility

The group uses the menu radio group pattern.

AudioTrackRadioGroup.Options receives its accessible label from the label prop on AudioTrackRadioGroup.Root or defaults to Audio. Override it with aria-label or aria-labelledby on AudioTrackRadioGroup.Options.

Examples

Basic usage

import { Container, createPlayer, Menu } from '@videojs/react';
import { HlsJsVideo } from '@videojs/react/media/hlsjs-video';
import { AudioTrackRadioGroup } from '@videojs/react/ui/audio-track-radio-group';
import { videoFeatures } from '@videojs/react/video';
import type { ReactNode } from 'react';

const { Player } = createPlayer({ features: videoFeatures });
const src = 'https://stream.mux.com/s41JYeqIpBMBzE4OzxDyGR2yrp2hD1CQ6gJN9SlVGDQ.m3u8';

function AudioMenu(): ReactNode {
  return (
    <Menu.Root side="top" align="end">
      <AudioTrackRadioGroup.Root>
        <Menu.Trigger className="settings-trigger" render={<button type="button" />}>
          Audio
          <AudioTrackRadioGroup.Value className="menu-hint" />
        </Menu.Trigger>
        <Menu.Popup className="menu">
          <Menu.Content>
            <AudioTrackRadioGroup.Options
              className="menu-group"
              renderItem={(props, item) => (
                <Menu.RadioItem {...props} className="menu-item">
                  {item.label}
                  <Menu.ItemIndicator checked={item.checked} forceMount className="menu-indicator">

                  </Menu.ItemIndicator>
                </Menu.RadioItem>
              )}
            />
          </Menu.Content>
        </Menu.Popup>
      </AudioTrackRadioGroup.Root>
    </Menu.Root>
  );
}

export default function BasicUsage() {
  return (
    <Player>
      <Container className="media-container">
        <HlsJsVideo src={src} autoPlay crossOrigin="anonymous" muted playsInline loop />
        <div className="menu-bar">
          <AudioMenu />
        </div>
      </Container>
    </Player>
  );
}

API Reference

Root

Owns audio-track option state and shares it with an enclosing menu. Does not render a DOM element.

Props

PropTypeDefaultDetails
disabledbooleanfalse
formatTrackstring) | functionformatTrackLabel
labelobject''

State

State is accessible via the render, className, and style props.

PropertyTypeDetails
label{ key: string; text: string } | string
valuestring
optionsreadonly Option[]
disabledboolean
hiddenboolean
availability'available' | 'unavailable'

Data attributes

AttributeTypeDetails
data-audio-trackstring
data-disabled
data-hidden
data-availability'available' | 'unavailable'

Options

Renders menu radio items for the player's available audio tracks.

Props

PropTypeDefaultDetails
classNamestring | ((state: AudioTrackRadioGroupCore.State) => string | undefined)
renderReactElement | ((props: HTMLProps, state: AudioTrackRadioGroupCore.State) => ReactElement | null)
renderItem((props: AudioTrackRadioGroupItemProps, state: AudioTrackRadioGroupItemState) => ReactElement)
styleCSSProperties | ((state: AudioTrackRadioGroupCore.State) => CSSProperties | undefined)

Value

Displays the selected audio-track label.

Props

PropTypeDefaultDetails
classNamestring | ((state: AudioTrackOptionsResult) => string | undefined)
renderReactElement | ((props: HTMLProps, state: AudioTrackOptionsResult) => ReactElement | null)
styleCSSProperties | ((state: AudioTrackOptionsResult) => CSSProperties | undefined)