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

# Playlist

> Render the player's content list and let users jump between items.

> [tab] Preview

> [tab] Code
>
> ```jsx Playlist.jsx theme={null}
> "use client";
>
> import { newEvent } from "@/lib/newEvent";
> import { NowPlayingMarkerIcon } from "@/registry/react/Icons";
> import { usePlayer, usePlayerSelector } from "@/registry/react/PlayerProvider";
>
> export function Playlist() {
>   const player = usePlayer();
>   const content = usePlayerSelector((p) => p.content);
>   const contentIndex = usePlayerSelector((p) => p.contentIndex);
>   return (
>     <ul style={{ listStyle: "none", margin: 0, padding: 0 }}>
>       {content.map((item, index) => (
>         <li key={index}>
>           <button
>             type="button"
>             aria-current={contentIndex === index}
>             aria-label={`Play ${item.title}`}
>             style={{ display: "flex", alignItems: "center", gap: "0.5rem", width: "100%" }}
>             onClick={() => {
>               player.onEvent(
>                 newEvent({
>                   type: "PressedPlaylistItem",
>                   description: "A playlist item was pressed.",
>                   index,
>                 }),
>               );
>             }}
>           >
>             <span style={{ display: "inline-flex", width: "1rem", justifyContent: "center" }}>
>               {contentIndex === index ? <NowPlayingMarkerIcon size={16} /> : index + 1}
>             </span>
>             <span>{item.title}</span>
>           </button>
>         </li>
>       ))}
>     </ul>
>   );
> }
> ```

## Installation

```bash npm theme={null}
npx @beyondwords/cli components add playlist
```

```bash pnpm theme={null}
pnpm dlx @beyondwords/cli components add playlist
```

```bash yarn theme={null}
yarn dlx @beyondwords/cli components add playlist
```

```bash bun theme={null}
bunx --bun @beyondwords/cli components add playlist
```

## Usage

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

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

The component maps over `content` from the surrounding
[`PlayerProvider`](https://docs.beyondwords.io/components/react/player-provider). It renders a button per item and
marks the active one (`contentIndex`) with a now-playing icon. Pressing an item emits a
`PressedPlaylistItem` event (built with [`newEvent`](https://docs.beyondwords.io/components/react/new-event))
carrying its `index`.

> [!NOTE]
>
> The event is emitted rather than setting `player.contentIndex` directly. This
> lets the player handle ads and outros correctly when switching tracks.

## Reference

| | |
| - | - |
| **Props** | None |
| **Player state read** | `content`, `contentIndex` |
| **Events emitted** | `PressedPlaylistItem` (carries the item's `index`) |
| **Requires** | a [`PlayerProvider`](https://docs.beyondwords.io/components/react/player-provider) ancestor |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.