# media-buffering-indicator

Loading indicator that displays when the video player is buffering or waiting for data

## Import

```ts
import '@videojs/html/ui/buffering-indicator';
```

## Anatomy

```html
<media-buffering-indicator></media-buffering-indicator>
```

## Behavior

Shows a loading indicator when the media is waiting to buffer and not paused, but only after a configurable `delay` (default 500ms). This delay prevents the indicator from flickering during brief stalls. The indicator hides immediately when buffering ends.

## Styling

Hide and show the indicator based on the `data-visible` attribute.

## Examples

### Basic Usage

**index.html**

```html
<video-player class="video-player">
  <media-container>
    <video src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4" autoplay muted playsinline loop></video>
    <media-buffering-indicator class="media-buffering-indicator">
      <div class="spinner"></div>
    </media-buffering-indicator>
  </media-container>
</video-player>
```

**index.css**

```css
.video-player media-container {
  position: relative;
  display: flex;
  width: 100%;
  height: 100%;
}

.media-buffering-indicator {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.spinner {
  display: none;
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: buffering-spin 0.8s linear infinite;
}

.media-buffering-indicator[data-visible] .spinner {
  display: block;
}

@keyframes buffering-spin {
  to {
    transform: rotate(360deg);
  }
}
```

**index.ts**

```ts
import '@videojs/html/video/player';
import '@videojs/html/ui/container';
import '@videojs/html/ui/buffering-indicator';
```

## API Reference

### Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `delay` | `number` | `500` | Delay in milliseconds before the indicator becomes visible. |

### State

State is reflected as data attributes for CSS styling.

| Property | Type | Description |
| --- | --- | --- |
| `visible` | `boolean` | Whether the indicator should be visible. True after the delay elapses while media is waiting and not paused. |

### Data attributes

| Attribute | Description |
| --- | --- |
| `data-visible` | Present when the buffering indicator is visible (after delay). |

---

HTML documentation: https://videojs.org/docs/framework/html/llms.txt
All documentation: https://videojs.org/llms.txt
