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

# Setup

> Install the custom elements with the BeyondWords CLI and build your first player.

export const WebComponentsDemo = ({name}) => {
  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 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: false,
    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: false,
    duration: 98,
    audio: [{
      id: "audio-1",
      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: false,
    duration: 152,
    audio: [{
      id: "audio-1",
      url: "/images/player-ui/demo-silent.mp3",
      contentType: "audio/mpeg",
      duration: 152
    }],
    video: [],
    summarization: {
      audio: [],
      video: []
    },
    segments: []
  }];
  const MOCK_ADVERTS = [{
    id: "advert-1",
    type: "native",
    placement: "pre-roll",
    vastUrl: null,
    clickThroughUrl: "https://sponsor.example.com",
    imageUrl: "/images/player-ui/demo-cover.svg",
    textColor: "#ffffff",
    backgroundColor: "#943bfc",
    iconColor: "#ffffff",
    audio: [{
      id: "advert-audio-1",
      url: "/images/player-ui/demo-silent.mp3",
      contentType: "audio/mpeg",
      duration: 8
    }],
    video: []
  }];
  const content = JSON.stringify(MOCK_CONTENT).replace(/'/g, "&#39;");
  const playlistContent = JSON.stringify(MOCK_PLAYLIST).replace(/'/g, "&#39;");
  const adverts = JSON.stringify(MOCK_ADVERTS).replace(/'/g, "&#39;");
  const DEMOS = {
    "play-pause-button": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${content}'><bw-play-pause-button></bw-play-pause-button></bw-player-provider>`,
    "time-indicator": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${content}'><bw-time-indicator></bw-time-indicator></bw-player-provider>`,
    "prev-segment-button": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${content}'><bw-prev-segment-button></bw-prev-segment-button></bw-player-provider>`,
    "next-segment-button": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${content}'><bw-next-segment-button></bw-next-segment-button></bw-player-provider>`,
    "prev-seconds-button": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${content}'><bw-prev-seconds-button></bw-prev-seconds-button></bw-player-provider>`,
    "next-seconds-button": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${content}'><bw-next-seconds-button></bw-next-seconds-button></bw-player-provider>`,
    "playback-rate-button": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${content}'><bw-playback-rate-button></bw-playback-rate-button></bw-player-provider>`,
    "content-title": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${content}'><bw-content-title></bw-content-title></bw-player-provider>`,
    "call-to-action": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${content}'><bw-call-to-action></bw-call-to-action></bw-player-provider>`,
    "download-button": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${content}'><bw-download-button></bw-download-button></bw-player-provider>`,
    "beyondwords-logo": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${content}'><bw-beyondwords-logo></bw-beyondwords-logo></bw-player-provider>`,
    "prev-track-button": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${playlistContent}'><bw-prev-track-button></bw-prev-track-button></bw-player-provider>`,
    "next-track-button": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${playlistContent}'><bw-next-track-button></bw-next-track-button></bw-player-provider>`,
    "playlist": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${playlistContent}'><bw-playlist></bw-playlist></bw-player-provider>`,
    "feature-image": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${content}'><div style="width:100%;max-width:20rem;min-width:15rem;overflow:hidden;border-radius:0.5rem"><bw-feature-image></bw-feature-image></div></bw-player-provider>`,
    "progress-bar": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${content}'><div style="display:flex;flex-direction:row;align-items:center;min-width:30rem"><bw-progress-bar></bw-progress-bar></div></bw-player-provider>`,
    "advert-link": `<bw-player-provider data-show-user-interface="false" data-analytics-consent="none" data-content='${content}' data-adverts='${adverts}' data-advert-index="0"><bw-advert-link></bw-advert-link></bw-player-provider>`,
    "standard-player": `<bw-standard-player-provider data-show-user-interface="false" data-analytics-consent="none" data-project-id="9504" data-content-id="ba00ef51-03ac-4a85-8b98-e45c957e8ef8"><bw-standard-player-bar><bw-standard-play-pause-button></bw-standard-play-pause-button><bw-standard-player-info><bw-standard-call-to-action></bw-standard-call-to-action><bw-standard-duration></bw-standard-duration></bw-standard-player-info><bw-standard-playback-controls><bw-standard-playback-rate-button></bw-standard-playback-rate-button><bw-standard-prev-segment-button></bw-standard-prev-segment-button><bw-standard-next-segment-button></bw-standard-next-segment-button><bw-standard-time-indicator></bw-standard-time-indicator><bw-standard-progress-bar></bw-standard-progress-bar><bw-standard-close-widget-button></bw-standard-close-widget-button></bw-standard-playback-controls><bw-standard-beyondwords-logo></bw-standard-beyondwords-logo></bw-standard-player-bar></bw-standard-player-provider>`,
    "minimal-player": `<bw-minimal-player-provider data-show-user-interface="false" data-analytics-consent="none" data-project-id="9504" data-content-id="ba00ef51-03ac-4a85-8b98-e45c957e8ef8"><bw-minimal-player-bar><bw-minimal-play-pause-button></bw-minimal-play-pause-button><bw-minimal-call-to-action></bw-minimal-call-to-action><bw-minimal-prev-seconds-button data-seconds="10"></bw-minimal-prev-seconds-button><bw-minimal-playback-rate-menu></bw-minimal-playback-rate-menu><bw-minimal-current-time></bw-minimal-current-time></bw-minimal-player-bar></bw-minimal-player-provider>`,
    "playlist-player": `<bw-playlist-player-provider data-show-user-interface="false" data-analytics-consent="none" data-project-id="9504" data-playlist-id="153102"><bw-playlist-player-root><bw-playlist-player-bar><bw-playlist-play-pause-button></bw-playlist-play-pause-button><bw-playlist-player-info><bw-playlist-call-to-action></bw-playlist-call-to-action><bw-playlist-duration></bw-playlist-duration></bw-playlist-player-info><bw-playlist-playback-controls><bw-playlist-playback-rate-button></bw-playlist-playback-rate-button><bw-playlist-prev-track-button></bw-playlist-prev-track-button><bw-playlist-next-track-button></bw-playlist-next-track-button><bw-playlist-time-indicator></bw-playlist-time-indicator><bw-playlist-progress-bar></bw-playlist-progress-bar></bw-playlist-playback-controls><bw-playlist-toggle-button></bw-playlist-toggle-button></bw-playlist-player-bar><bw-playlist-list></bw-playlist-list></bw-playlist-player-root></bw-playlist-player-provider>`,
    "video-player": `<bw-video-player-provider data-show-user-interface="false" data-analytics-consent="none" data-video="true" data-project-id="54009" data-content-id="5ab6a5e1-689c-4103-962d-e7e68a4258ff"><bw-video-feature-image></bw-video-feature-image><bw-video-control-bar><bw-video-prev-seconds-button data-color="white" data-seconds="10"></bw-video-prev-seconds-button><bw-video-play-pause-button data-color="white" data-size="56"></bw-video-play-pause-button><bw-video-next-seconds-button data-color="white" data-seconds="10"></bw-video-next-seconds-button></bw-video-control-bar><bw-video-widget-bar><bw-video-play-pause-button></bw-video-play-pause-button><bw-video-widget-controls><bw-video-playback-rate-button></bw-video-playback-rate-button><bw-video-prev-seconds-button data-seconds="10"></bw-video-prev-seconds-button><bw-video-next-seconds-button data-seconds="10"></bw-video-next-seconds-button><bw-video-time-indicator></bw-video-time-indicator><bw-video-progress-bar></bw-video-progress-bar><bw-video-close-widget-button></bw-video-close-widget-button></bw-video-widget-controls></bw-video-widget-bar></bw-video-player-provider>`,
    "vertical-video-player": `<bw-video-player-provider data-show-user-interface="false" data-analytics-consent="none" data-video="true" data-aspect="9/16" data-height="480" data-project-id="54009" data-content-id="5ab6a5e1-689c-4103-962d-e7e68a4258ff"><bw-video-feature-image></bw-video-feature-image><bw-video-control-bar><bw-video-prev-seconds-button data-color="white" data-seconds="10"></bw-video-prev-seconds-button><bw-video-play-pause-button data-color="white" data-size="56"></bw-video-play-pause-button><bw-video-next-seconds-button data-color="white" data-seconds="10"></bw-video-next-seconds-button></bw-video-control-bar><bw-video-widget-bar><bw-video-play-pause-button></bw-video-play-pause-button><bw-video-widget-controls><bw-video-playback-rate-button></bw-video-playback-rate-button><bw-video-prev-seconds-button data-seconds="10"></bw-video-prev-seconds-button><bw-video-next-seconds-button data-seconds="10"></bw-video-next-seconds-button><bw-video-time-indicator></bw-video-time-indicator><bw-video-progress-bar></bw-video-progress-bar><bw-video-close-widget-button></bw-video-close-widget-button></bw-video-widget-controls></bw-video-widget-bar></bw-video-player-provider>`
  };
  const markup = DEMOS[name];
  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'
  }}>
      {markup ? <div dangerouslySetInnerHTML={{
    __html: markup
  }} /> : <p className="text-sm">No preview available for “{name}”.</p>}
    </div>;
};

The elements ship as a shadcn registry. Add them with the CLI and the source is
copied into your project. They also need the BeyondWords player script on the
page.

## Prerequisites

* A project where you can run `npx` commands and serve ES modules. The CLI
  copies the element source into your project.
* A BeyondWords **project ID** and a **source ID** (or content ID). The examples
  below use a public demo project.

## Load the player script

The elements expect the BeyondWords player as a global `BeyondWords`. Add the
player UMD script to your page so it loads before the provider connects:

```html theme={null}
<script async src="https://proxy.beyondwords.io/npm/@beyondwords/player@latest/dist/umd.js"></script>
```

## Add a component

Add the [Play Pause Button](/player-ui/html/play-pause-button). No configuration
is needed. The `--html` flag selects the HTML registry, and the CLI resolves
dependencies automatically, so this also pulls in
[Player Provider](/player-ui/html/player-provider) and
[New Event](/player-ui/html/new-event).

```bash theme={null}
npx @beyondwords/cli components add play-pause-button --html
```

The CLI copies the files to `components/beyondwords/` by default (it asks
first), or respects your aliases if the project has a `components.json`. The
examples in these docs import from `@/registry/html/`. Adjust the paths to
wherever the files landed, and serve them through a bundler or an import map so
the browser can resolve them.

## Build your first player

Each module calls `customElements.define`, so importing it registers the tag.
Nest your controls inside a `<bw-player-provider>`, which mounts the player and
shares it with the elements inside. `data-show-user-interface="false"` hides the
player's built-in UI so yours is the only one on the page.

```html theme={null}
<bw-player-provider data-project-id="9504" data-content-id="ba00ef51-03ac-4a85-8b98-e45c957e8ef8" data-show-user-interface="false">
  <bw-play-pause-button></bw-play-pause-button>
</bw-player-provider>

<script type="module">
  import "@/registry/html/PlayerProvider";
  import "@/registry/html/PlayPauseButton";
</script>
```

Here's that button running live:

<WebComponentsDemo name="play-pause-button" />

It looks plain because the elements are minimal by design;
[Theming](/player-ui/html/theming) shows how to make it yours. Add more
controls the same way: import the module, nest the element inside the provider.

To build your own controls, extend `BwPlayerConsumer`, which resolves the
player instance from the nearest `<bw-player-provider>`. See
[Player Provider](/player-ui/html/player-provider) for the pattern, and
[New Event](/player-ui/html/new-event) for emitting player events.

## Using the shadcn CLI instead (optional)

The registry also works with the shadcn CLI directly. Add components by full
URL:

```bash theme={null}
npx shadcn add https://ui.beyondwords.io/r/html/play-pause-button.json
```

Or register the registry namespace once in your `components.json`, then use
short names:

```json components.json theme={null}
{
  "registries": {
    "@beyondwords-html": "https://ui.beyondwords.io/r/html/{name}.json"
  }
}
```

```bash theme={null}
npx shadcn add @beyondwords-html/play-pause-button
```

## Next steps

<CardGroup cols={2}>
  <Card title="Theming" href="/player-ui/html/theming">Style the elements to match your brand.</Card>
  <Card title="Player Provider" href="/player-ui/html/player-provider">Provide and consume the player.</Card>
  <Card title="Examples" href="/player-ui/html/standard-player">Start from a complete, pre-built player.</Card>
  <Card title="Troubleshooting" href="/player-ui/html/troubleshooting">Fix common setup issues.</Card>
</CardGroup>
