Skip to content

Commit

Permalink
docs: add custom player demo
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Apr 19, 2024
1 parent e7ab569 commit c381613
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export default function Page() {
```


### Custom Player
### Custom Player ([Demo](https://next-video-demo.vercel.app/custom-player))

You can customize the player by passing a custom player component to the `as` prop.
The custom player component accepts the following props:
Expand All @@ -254,23 +254,31 @@ The custom player component accepts the following props:

```tsx
import Video from 'next-video';
import { ReactPlayerAsVideo } from './player';
import ReactPlayer from './player';
import awesomeVideo from '/videos/awesome-video.mp4';

export default function Page() {
return <Video as={ReactPlayerAsVideo} src={awesomeVideo} />;
return <Video as={ReactPlayer} src={awesomeVideo} />;
}
```

```tsx
// player.js
import ReactPlayer from 'react-player';
// player.tsx
'use client';

export function ReactPlayerAsVideo(props) {
let { asset, src, poster, blurDataURL, ...rest } = props;
import ReactPlayer, { ReactPlayerProps } from 'react-player';

export default function Player(props: ReactPlayerProps) {
let { asset, src, poster, blurDataURL, thumbnailTime, ...rest } = props;
let config = { file: { attributes: { poster } } };

return <ReactPlayer url={src} config={config} {...rest} />;
return <ReactPlayer
url={src}
config={config}
width="100%"
height="100%"
{...rest}
/>;
}
```

Expand Down
5 changes: 2 additions & 3 deletions examples/default-provider/app/custom-player/player.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use client';

import ReactPlayer from 'react-player';
import ReactPlayer, { ReactPlayerProps } from 'react-player';

export default function Player(props) {
export default function Player(props: ReactPlayerProps) {
let { asset, src, poster, blurDataURL, thumbnailTime, ...rest } = props;

let config = { file: { attributes: { poster } } };

return <ReactPlayer
Expand Down

0 comments on commit c381613

Please sign in to comment.