FrameworkStyle

MuteButton

A button component for muting and unmuting audio playback

Anatomy

<MuteButton />

Behavior

Toggles mute on and off, and exposes a derived volumeLevel based on the current volume and mute state.

Styling

Style the button based on muted state:

media-mute-button[data-muted] .icon-muted { display: inline; }
media-mute-button:not([data-muted]) .icon-unmuted { display: inline; }

Use data-volume-level for multi-level icon switching:

media-mute-button[data-volume-level="off"] .icon-off { display: inline; }
media-mute-button[data-volume-level="low"] .icon-low { display: inline; }
media-mute-button[data-volume-level="medium"] .icon-medium { display: inline; }
media-mute-button[data-volume-level="high"] .icon-high { display: inline; }

Accessibility

Renders a <button> with an automatic aria-label: “Unmute” when muted, “Mute” when unmuted. Override with the label prop. Keyboard activation: Enter / Space.

Examples

Basic Usage

import { createPlayer, features, MuteButton } from '@videojs/react';
import { Video } from '@videojs/react/video';

import './BasicUsage.css';

const Player = createPlayer({ features: [...features.video] });

export default function BasicUsage() {
  return (
    <Player.Provider>
      <Player.Container className="react-mute-button-basic">
        <Video
          src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
          autoPlay
          muted
          playsInline
          loop
        />
        <MuteButton
          className="react-mute-button-basic__button"
          render={(props, state) => <button {...props}>{state.muted ? 'Unmute' : 'Mute'}</button>}
        />
      </Player.Container>
    </Player.Provider>
  );
}

Volume Levels

import { createPlayer, features, MuteButton } from '@videojs/react';
import { Video } from '@videojs/react/video';

import './VolumeLevels.css';

const Player = createPlayer({ features: [...features.video] });

export default function VolumeLevels() {
  return (
    <Player.Provider>
      <Player.Container className="react-mute-button-volume-levels">
        <Video
          src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
          autoPlay
          muted
          playsInline
          loop
        />
        <MuteButton
          className="react-mute-button-volume-levels__button"
          render={(props, state) => (
            <button {...props}>
              {state.volumeLevel === 'off'
                ? 'Off'
                : state.volumeLevel === 'low'
                  ? 'Low'
                  : state.volumeLevel === 'medium'
                    ? 'Medium'
                    : 'High'}
            </button>
          )}
        />
      </Player.Container>
    </Player.Provider>
  );
}

API Reference

Props

Prop Type Default
disabled boolean false
label string | function ''

State

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

Property Type
volumeLevel 'off' | 'low' | 'medium' | 'high'
muted boolean

Data attributes

Attribute Description
data-muted Present when the media is muted.
data-volume-level Indicates the volume level.
VideoJS