> ## 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.

# Previous Track Button

> Skips to the previous track in a playlist.

export const PrevTrackButtonDemo = () => {
  const MOCK_PLAYLIST = [{
    id: "7a974fb1-1b89-4be3-a25d-4ad286d5305b",
    title: "Part 1: The newsroom shift",
    imageUrl: "/images/player-ui/demo-cover.svg",
    sourceUrl: "https://beyondwords.io",
    sourceId: "demo",
    adsEnabled: true,
    duration: 124,
    audio: [{
      id: "audio-1",
      url: "/images/player-ui/demo-silent.mp3",
      contentType: "audio/mpeg",
      duration: 124
    }],
    video: [],
    summarization: {
      audio: [],
      video: []
    },
    segments: []
  }, {
    id: "129e7681-fa4d-4526-8be9-d27c946a5023",
    title: "Part 2: Voices at scale",
    imageUrl: "/images/player-ui/demo-cover.svg",
    sourceUrl: "https://beyondwords.io",
    sourceId: "demo",
    adsEnabled: true,
    duration: 98,
    audio: [{
      id: "audio-2",
      url: "/images/player-ui/demo-silent.mp3",
      contentType: "audio/mpeg",
      duration: 98
    }],
    video: [],
    summarization: {
      audio: [],
      video: []
    },
    segments: []
  }, {
    id: "e9f2257c-14cf-46c0-bab6-bcaa9e229775",
    title: "Part 3: What comes next",
    imageUrl: "/images/player-ui/demo-cover.svg",
    sourceUrl: "https://beyondwords.io",
    sourceId: "demo",
    adsEnabled: true,
    duration: 152,
    audio: [{
      id: "audio-3",
      url: "/images/player-ui/demo-silent.mp3",
      contentType: "audio/mpeg",
      duration: 152
    }],
    video: [],
    summarization: {
      audio: [],
      video: []
    },
    segments: []
  }];
  const newEvent = props => ({
    id: crypto.randomUUID(),
    createdAt: new Date().toISOString(),
    status: "pending",
    initiatedBy: "user",
    ...props
  });
  const [target, setTarget] = useState(null);
  const [player, setPlayer] = useState(null);
  useEffect(() => {
    if (!target) return;
    let instance;
    const init = () => {
      instance = new window.BeyondWords.Player({
        target,
        content: MOCK_PLAYLIST,
        widgetStyle: "none",
        showUserInterface: false,
        analyticsConsent: "none"
      });
      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 type="button" aria-label="Previous track" onClick={() => {
    player.onEvent(newEvent({
      type: "PressedPrevTrack",
      description: "The previous track button was pressed."
    }));
  }}>
          <svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
            <path fillRule="evenodd" d="M5.4 8.35a1.05 1.05 0 0 1 2.1 0v7.3a1.05 1.05 0 0 1 -2.1 0ZM17.5 8.08 Q18.55 7.5 18.55 8.7 L18.55 15.3 Q18.55 16.5 17.5 15.92 L11.71 12.73 Q10.4 12 11.71 11.27Z" />
          </svg>
        </button>}
    </div>;
};

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

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

    import { newEvent } from "@/lib/newEvent";
    import { PreviousTrackIcon } from "@/registry/react/Icons";
    import { usePlayer } from "@/registry/react/PlayerProvider";

    export function PrevTrackButton() {
      const player = usePlayer();
      return (
        <button
          type="button"
          aria-label="Previous track"
          onClick={() => {
            player.onEvent(
              newEvent({
                type: "PressedPrevTrack",
                description: "The previous track button was pressed.",
              }),
            );
          }}
        >
          <PreviousTrackIcon size={24} />
        </button>
      );
    }
    ```
  </Tab>
</Tabs>

## Installation

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

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

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

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

## Usage

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

export function Player() {
  return (
    <PlayerProvider args={{ projectId: 9504, playlistId: 153102, showUserInterface: false }}>
      <PrevTrackButton />
    </PlayerProvider>
  );
}
```

On click the button emits a `PressedPrevTrack` event (built with
[`newEvent`](/player-ui/react/new-event)) on the surrounding
[`PlayerProvider`](/player-ui/react/player-provider). It's intended for playlist
sources, where the player moves to the previous track.

## Reference

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