> ## Documentation Index
> Fetch the complete documentation index at: https://docs.beyondwords.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Playback Rate Button

> Toggles the player's playback speed between 1x and 1.5x.

export const PlaybackRateButtonDemo = () => {
  const MOCK_CONTENT = [{
    id: "demo-1",
    title: "How AI voices are changing publishing",
    imageUrl: "/images/player-ui/demo-cover.svg",
    sourceUrl: "https://beyondwords.io",
    sourceId: "demo",
    adsEnabled: false,
    duration: 124,
    audio: [{
      id: "audio-1",
      url: "/images/player-ui/demo-silent.mp3",
      contentType: "audio/mpeg",
      duration: 124
    }],
    video: [],
    summarization: {
      audio: [],
      video: []
    },
    segments: []
  }];
  const [target, setTarget] = useState(null);
  const [player, setPlayer] = useState(null);
  const [playbackRate, setPlaybackRate] = useState(1);
  useEffect(() => {
    if (!target) return;
    let instance;
    const init = () => {
      instance = new window.BeyondWords.Player({
        target,
        content: MOCK_CONTENT,
        widgetStyle: "none",
        showUserInterface: false,
        analyticsConsent: "none"
      });
      const sync = () => setPlaybackRate(instance.playbackRate);
      instance.addEventListener("<any>", sync);
      sync();
      setPlayer(instance);
    };
    if (window.BeyondWords) init(); else window.addEventListener("BeyondWordsReady", init);
    return () => {
      window.removeEventListener("BeyondWordsReady", init);
      if (instance) instance.destroy();
    };
  }, [target]);
  return <div className="not-prose flex w-full items-center justify-center rounded-lg border p-10" style={{
    minHeight: "16rem",
    fontFamily: 'ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif'
  }}>
      <div ref={setTarget} style={{
    display: "none"
  }} />
      {player && <button onClick={() => {
    player.playbackRate = playbackRate === 1 ? 1.5 : 1;
  }}>
          {playbackRate}x
        </button>}
    </div>;
};

<Tabs>
  <Tab title="Preview">
    <PlaybackRateButtonDemo />
  </Tab>

  <Tab title="Code">
    ```jsx PlaybackRateButton.jsx theme={null}
    "use client";

    import { usePlayer, usePlayerSelector } from "@/registry/react/PlayerProvider";

    export function PlaybackRateButton() {
      const player = usePlayer();
      const playbackRate = usePlayerSelector((p) => p.playbackRate);
      return (
        <button
          onClick={() => {
            player.playbackRate = playbackRate === 1 ? 1.5 : 1;
          }}
        >
          {playbackRate}x
        </button>
      );
    }
    ```
  </Tab>
</Tabs>

## Installation

<CodeGroup>
  ```bash npm theme={null}
  npx @beyondwords/cli components add playback-rate-button
  ```

  ```bash pnpm theme={null}
  pnpm dlx @beyondwords/cli components add playback-rate-button
  ```

  ```bash yarn theme={null}
  yarn dlx @beyondwords/cli components add playback-rate-button
  ```

  ```bash bun theme={null}
  bunx --bun @beyondwords/cli components add playback-rate-button
  ```
</CodeGroup>

## Usage

```tsx theme={null}
import { PlayerProvider } from '@/registry/react/PlayerProvider';
import { PlaybackRateButton } from '@/registry/react/PlaybackRateButton';

export function Player() {
  return (
    <PlayerProvider args={{ projectId: 9504, contentId: "ba00ef51-03ac-4a85-8b98-e45c957e8ef8", showUserInterface: false }}>
      <PlaybackRateButton />
    </PlayerProvider>
  );
}
```

The button reads `playbackRate` from the surrounding
[`PlayerProvider`](/player-ui/react/player-provider). On click, it sets
`player.playbackRate` directly on the instance, toggling between `1` and
`1.5`. The current rate renders as the label (e.g. `1x`). Adjust the toggle
logic to expose whatever speeds you want.

## Reference

|                       |                                                                 |
| --------------------- | --------------------------------------------------------------- |
| **Props**             | None                                                            |
| **Player state read** | `playbackRate`                                                  |
| **Events emitted**    | None. Sets `player.playbackRate` directly                       |
| **Requires**          | a [`PlayerProvider`](/player-ui/react/player-provider) ancestor |
