Skip to content
FrameworkStyle

CastButton

Accessible Cast toggle button with state reflection and keyboard support

Anatomy

<CastButton />

Behavior

Toggles a Google Cast session. Clicking the button while disconnected opens the Cast device picker; clicking while connected ends the session.

The button does nothing when availability is not 'available' — for example, when no Chromecast is on the network, or on browsers that don’t support Cast.

Styling

Style based on cast state and availability:

React renders a <button> element. Add a className to style it:

/* During an active session */
.cast-button[data-cast-state="connected"] {
  color: blue;
}

/* Hide when Cast is unsupported (non-Chromium browsers) */
.cast-button[data-availability="unsupported"] {
  display: none;
}

Accessibility

Renders a <button> with an automatic aria-label:

Cast state Default label
'disconnected' ”Start casting”
'connecting' ”Connecting”
'connected' ”Stop casting”

Override with the label prop. Keyboard activation: Enter / Space.

Examples

Basic Usage

import { CastButton, createPlayer } from '@videojs/react';
import { HlsVideo } from '@videojs/react/media/hls-video';
import { videoFeatures } from '@videojs/react/video';

const Player = createPlayer({ features: videoFeatures });

export default function BasicUsage() {
  return (
    <Player.Provider>
      <Player.Container className="media-container">
        <HlsVideo
          src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM.m3u8"
          autoPlay
          muted
          playsInline
          loop
        />
        <CastButton
          className="media-cast-button"
          render={(props, state) => (
            <button {...props}>{state.castState === 'connected' ? 'Stop casting' : 'Start casting'}</button>
          )}
        />
      </Player.Container>
    </Player.Provider>
  );
}

API Reference

Props

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

State

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

Property Type Details
castState 'disconnected' | 'connecting' | 'conn...
availability 'available' | 'unavailable' | 'unsupp...
label string

Data attributes

Attribute Type Details
data-cast-state 'disconnected' | 'connecting' | 'conn...
data-availability 'available' | 'unavailable' | 'unsupp...