# Playback

Play/pause state and actions for the player store

Controls play/pause state and tracks whether playback has started or is stalled.

When the media has `autoplay`, `autoplaying` is true from the moment a source loads until playback starts. It also turns false when the autoplay is refused: browsers don’t announce that, so it shows as the media being able to play through but staying paused, and embeds report it with a `pause` or `error` event. Treat it as playback about to begin: the play button shows pause and the buffering indicator shows while it’s true, and `pause()` cancels it.

## Import

```ts
import { playbackFeature } from '@videojs/html';
```

The `audioFeatures`, `liveAudioFeatures`, `liveVideoFeatures`, and `videoFeatures` [feature bundles](../../guides/presets.md) include this feature.

## API Reference

### State

| Property | Type | Description |
| --- | --- | --- |
| `paused` | `boolean` | Whether playback is paused. |
| `ended` | `boolean` | Whether playback has reached the end. |
| `started` | `boolean` | Whether playback has started (played or seeked). |
| `waiting` | `boolean` | Whether playback is stalled waiting for data. |
| `autoplay` | `boolean` | Whether the media starts playing on its own once it can. |
| `autoplaying` | `boolean` | Whether the media is trying to autoplay: `autoplay` is set, and playback hasn't started yet. Clears when playback starts, when `pause()` cancels it, and when the autoplay is refused. Browsers don't announce a refusal, so it shows as the media being able to play through but staying paused; embeds report one with a `pause` or `error` event. Controls treat it as playback that's about to begin. |

### Actions

| Action | Type | Description |
| --- | --- | --- |
| `play` | `() => Promise<void>` | Start playback. Updates `paused` immediately when the media starts. |
| `pause` | `() => void` | Pause playback. Updates `paused` immediately, and cancels a pending autoplay. |

### Selector

Pass `selectPlayback` to [`PlayerController`](./player-controller.md) to subscribe to playback state. Returns `undefined` if the playback feature is not configured.

**play-button.ts**

```ts
import { createPlayer, UIElement, selectPlayback } from '@videojs/html';
import { videoFeatures } from '@videojs/html/video';

const { PlayerController } = createPlayer({ features: videoFeatures });

class PlayButton extends UIElement {
  readonly #playback = new PlayerController(this, selectPlayback);
}
```