Skip to content

Commit

Permalink
docs: add slotted poster image element
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Feb 22, 2024
1 parent d20b4ba commit 96886d8
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,42 @@ export default function Page() {
}
```

This is a good solution but it will not provide the same level of optimization
as the automatic poster and blurDataURL by the default provider.

To get the same level of optimization you can use a slotted poster element.


### Slotted poster image element

Add a slotted poster image element
(like [`next/image`](https://nextjs.org/docs/app/api-reference/components/image))
to the video by passing it as a child with a `slot="poster"` attribute.

Now your image will get all the benefits of the used image component
and it will be nicely placed behind the video player controls.


```tsx
import Image from 'next/image';
import Video from 'next-video';
import awesomeVideo from '/videos/awesome-video.mp4';
import awesomePoster from '/images/awesome-poster.jpg';

export default function Page() {
return <Video src={awesomeVideo}>
<Image
slot="poster"
src={awesomePoster.src}
blurDataURL={awesomePoster.blurDataURL}
alt="Some peeps doing something awesome"
fill={true}
/>
</Video>;
}
```


### Custom Player

You can customize the player by passing a custom player component to the `as` prop.
Expand Down

0 comments on commit 96886d8

Please sign in to comment.