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

# Video playback

> Play Livepeer livestreams and video assets via HLS and WebRTC. Covers the React Player, HLS.js, and direct URL construction for custom players.

> [!TIP]
>
> Use the `@livepeer/react` Player for the simplest integration -- it handles HLS, WebRTC fallback, and JWT access control automatically. Use HLS.js or a custom player when you need full control over the player UI.

***

Livepeer delivers content over HLS (3-8 second latency) and WebRTC (sub-second latency). The `@livepeer/react` Player selects the best protocol automatically. For custom players, construct URLs directly from the `playbackId`.

React Player

## @livepeer/react Player

Install:

```bash theme={null}
npm install @livepeer/react
```

```tsx theme={null}
import * as Player from '@livepeer/react/player';

export const VideoPlayer = ({ playbackId }: { playbackId: string }) => (
  <Player.Root src={`https://livepeercdn.studio/hls/${playbackId}/index.m3u8`}>
    <Player.Container>
      <Player.Video />
      <Player.Controls />
    </Player.Container>
  </Player.Root>
);
```

For JWT-gated content, pass the signed token:

```tsx theme={null}
<Player.Root
  src={`https://livepeercdn.studio/hls/${playbackId}/index.m3u8`}
  jwt={jwtToken}
>
  <Player.Container>
    <Player.Video />
  </Player.Container>
</Player.Root>
```

The Player sends the JWT as the `Livepeer-Jwt` header for WebRTC and HLS, and as the `jwt` query parameter for MP4 playback.

Playback URLs

## Direct playback URLs

Construct playback URLs using the `playbackId` returned when you create a stream or asset:

<table>
  <thead>
    <tr>
      Format

      URL pattern

      Notes
    </tr>
  </thead>

  <tbody>
    <tr>
      **HLS (live)**

      `https://livepeercdn.studio/hls/{playbackId}/index.m3u8`

      Adaptive bitrate, 3-8 second latency
    </tr>

    <tr>
      **WebRTC (live)**

      `https://livepeercdn.studio/webrtc/{playbackId}`

      Sub-second latency; requires SDP negotiation
    </tr>

    <tr>
      **HLS (asset)**

      `https://livepeercdn.studio/asset/hls/{playbackId}/index.m3u8`

      VOD; available once `asset.ready` event fires
    </tr>

    <tr>
      **MP4 (asset)**

      `https://livepeercdn.studio/asset/mp4/{playbackId}/static360p0.mp4`

      Static MP4; rendition suffix varies by quality
    </tr>
  </tbody>
</table>

HLS.js

## HLS.js integration

```bash theme={null}
npm install hls.js
```

```javascript theme={null}
import Hls from 'hls.js';

const videoElement = document.querySelector('video');
const src = `https://livepeercdn.studio/hls/${playbackId}/index.m3u8`;

if (Hls.isSupported()) {
  const hls = new Hls({
    // For JWT-gated content
    xhrSetup: (xhr) => {
      xhr.setRequestHeader('Livepeer-Jwt', jwtToken);
    },
  });
  hls.loadSource(src);
  hls.attachMedia(videoElement);
} else if (videoElement.canPlayType('application/vnd.apple.mpegurl')) {
  // Native HLS (Safari, iOS)
  videoElement.src = `${src}?jwt=${jwtToken}`;
}
```

Asset Playback

## Confirming asset readiness

VOD assets are not playable until transcoding is complete. Subscribe to the `asset.ready` webhook, or poll the asset status:

```typescript theme={null}
const asset = await client.asset.get(assetId);

if (asset.asset.status.phase === 'ready') {
  const playbackUrl = `https://livepeercdn.studio/asset/hls/${asset.asset.playbackId}/index.m3u8`;
  // render player
} else if (asset.asset.status.phase === 'failed') {
  console.error('Transcoding failed:', asset.asset.status.error);
}
```

## Related pages

> [card] [Create a Livestream](/v2/developers/guides/video/create-livestream.md)
>
> Get a playback ID from a new stream.

> [card] [Access Control](/v2/developers/guides/video/access-control.md)
>
> Sign JWTs for gated content playback.


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