Poster
Poster image component that stays visible until playback starts
Anatomy
Import the component:
<Poster src="poster.jpg" alt="Video preview" /><media-poster>
<img src="poster.jpg" alt="Video preview" />
</media-poster>Examples
Basic Usage
import { createPlayer, features, PlayButton, Poster, Video } from '@videojs/react';
import './BasicUsage.css';
const Player = createPlayer({ features: [...features.video] });
export default function BasicUsage() {
return (
<Player.Provider>
<Player.Container className="poster-basic">
<Video src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4" playsInline />
<Poster
className="poster-basic__poster"
src="https://image.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/thumbnail.jpg"
/>
<PlayButton
className="poster-basic__button"
render={(props, state) => <button {...props}>{state.paused ? 'Play' : 'Pause'}</button>}
/>
</Player.Container>
</Player.Provider>
);
}
.poster-basic {
position: relative;
}
.poster-basic video {
width: 100%;
}
.poster-basic__poster {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
object-fit: cover;
pointer-events: none;
transition: opacity 0.25s;
}
.poster-basic__poster:not([data-visible]) {
opacity: 0;
}
.poster-basic__button {
position: absolute;
bottom: 10px;
left: 10px;
padding-block: 8px;
background: rgba(255, 255, 255, 0.75);
backdrop-filter: blur(10px);
color: black;
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 9999px;
padding-inline: 16px;
cursor: pointer;
}
<video-player class="poster-basic">
<video
src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
playsinline
></video>
<media-poster class="poster-basic__poster">
<img
src="https://image.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/thumbnail.jpg"
/>
</media-poster>
<media-play-button class="poster-basic__button">
<span class="show-when-paused">Play</span>
<span class="show-when-playing">Pause</span>
</media-play-button>
</video-player>
.poster-basic {
display: block;
position: relative;
}
.poster-basic video {
width: 100%;
}
.poster-basic__poster {
position: absolute;
inset: 0;
pointer-events: none;
transition: opacity 0.25s;
}
.poster-basic__poster:not([data-visible]) {
opacity: 0;
}
.poster-basic__poster img {
width: 100%;
height: 100%;
object-fit: cover;
}
.poster-basic__button {
position: absolute;
bottom: 10px;
left: 10px;
padding-block: 8px;
background: rgba(255, 255, 255, 0.75);
backdrop-filter: blur(10px);
color: black;
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 9999px;
padding-inline: 16px;
cursor: pointer;
}
.poster-basic__button .show-when-paused,
.poster-basic__button .show-when-playing {
display: none;
}
.poster-basic__button[data-paused] .show-when-paused {
display: inline;
}
.poster-basic__button:not([data-paused]) .show-when-playing {
display: inline;
}
import '@videojs/html/video/player';
import '@videojs/html/ui/play-button';
import '@videojs/html/ui/poster';
API Reference
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 | - |