media-buffering-indicator
A component that displays a loading indicator when media is buffering
Anatomy
<BufferingIndicator /><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
import { BufferingIndicator, createPlayer, features } from '@videojs/react';
import { Video } from '@videojs/react/video';
import './BasicUsage.css';
const Player = createPlayer({ features: [...features.video] });
export default function BasicUsage() {
return (
<Player.Provider>
<Player.Container className="react-buffering-indicator-basic">
<Video
src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
autoPlay
muted
playsInline
loop
/>
<BufferingIndicator
className="react-buffering-indicator-basic__overlay"
render={(props, state) => (
<div {...props}>{state.visible && <div className="react-buffering-indicator-basic__spinner" />}</div>
)}
/>
</Player.Container>
</Player.Provider>
);
}
.react-buffering-indicator-basic {
display: flex;
width: 100%;
height: 100%;
position: relative;
}
.react-buffering-indicator-basic__overlay {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
pointer-events: none;
z-index: 30;
}
.react-buffering-indicator-basic__overlay .react-buffering-indicator-basic__spinner {
display: none;
}
.react-buffering-indicator-basic__overlay[data-visible] .react-buffering-indicator-basic__spinner {
display: block;
}
.react-buffering-indicator-basic__spinner {
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;
}
@keyframes buffering-spin {
to {
transform: rotate(360deg);
}
}
<video-player class="html-buffering-indicator-basic">
<video
src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
autoplay
muted
playsinline
loop
></video>
<media-buffering-indicator class="html-buffering-indicator-basic__overlay">
<div class="html-buffering-indicator-basic__spinner"></div>
</media-buffering-indicator>
</video-player>
.html-buffering-indicator-basic {
display: flex;
width: 100%;
height: 100%;
position: relative;
}
.html-buffering-indicator-basic__overlay {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
pointer-events: none;
z-index: 30;
}
.html-buffering-indicator-basic__overlay .html-buffering-indicator-basic__spinner {
display: none;
}
.html-buffering-indicator-basic__overlay[data-visible] .html-buffering-indicator-basic__spinner {
display: block;
}
.html-buffering-indicator-basic__spinner {
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;
}
@keyframes buffering-spin {
to {
transform: rotate(360deg);
}
}
import '@videojs/html/video/player';
import '@videojs/html/ui/buffering-indicator';
API Reference
Props
| Prop | Type | Default | |
|---|---|---|---|
delay | number | 500 | |
| |||
State
State is accessible via the
render, className, and style props.
State is reflected as data attributes for CSS styling.
| Property | Type | |
|---|---|---|
visible | boolean | |
| ||
Data attributes
| Attribute | Description |
|---|---|
data-visible | Present when the buffering indicator is visible (after delay). |