Skip to content

Commit 35f845b

Browse files
authored
docs: add custom player controls section & example (#1942)
1 parent 6fa7049 commit 35f845b

File tree

1 file changed

+65
-2
lines changed

1 file changed

+65
-2
lines changed

README.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ Prop | Description | Default
7171
`style` | Add [inline styles](https://facebook.github.io/react/tips/inline-styles.html) to the root element | `{}`
7272
`light` | Set to `true` to show just the video thumbnail, which loads the full player on click<br />&nbsp;&nbsp;Pass in an image URL to override the preview image | `false`
7373
`fallback` | Element or component to use as a fallback if you are using lazy loading | `null`
74-
`wrapper` | Element or component to use as the container element | null
74+
`wrapper` | Element or component to use as the container element | `null`
7575
`playIcon` | Element or component to use as the play icon in light mode
76-
`previewTabIndex` | Set the tab index to be used on light mode | 0
76+
`previewTabIndex` | Set the tab index to be used on light mode | `0`
7777

7878
#### Callback props
7979

@@ -139,6 +139,69 @@ with the [HTMLMediaElement](https://developer.mozilla.org/en-US/docs/Web/API/HTM
139139

140140
### Advanced Usage
141141

142+
#### Custom player controls
143+
144+
By default ReactPlayer is a chromeless player. By setting the `controls` prop to `true`, you can enable the native controls for the player. However, the controls will look different for each player. The ones based on HTML5 media players will look like the native controls for that browser, while the ones based on third-party players will look like the native controls for that player.
145+
146+
```jsx
147+
<ReactPlayer src='https://www.youtube.com/watch?v=LXb3EKWsInQ' controls />
148+
```
149+
150+
If you like to add your own custom controls in a convenient way, you can use
151+
[Media Chrome](https://github.com/muxinc/media-chrome). Media Chrome is a library that provides a set of UI components that can be used to quickly build custom media controls.
152+
153+
##### Simple example ([Codesandbox](https://codesandbox.io/p/sandbox/react-player-media-chrome-simple-nl3pg4))
154+
155+
```tsx
156+
import ReactPlayer from "react-player";
157+
import {
158+
MediaController,
159+
MediaControlBar,
160+
MediaTimeRange,
161+
MediaTimeDisplay,
162+
MediaVolumeRange,
163+
MediaPlaybackRateButton,
164+
MediaPlayButton,
165+
MediaSeekBackwardButton,
166+
MediaSeekForwardButton,
167+
MediaMuteButton,
168+
MediaFullscreenButton,
169+
} from "media-chrome/react";
170+
171+
export default function Player() {
172+
return (
173+
<MediaController
174+
style={{
175+
width: "100%",
176+
aspectRatio: "16/9",
177+
}}
178+
>
179+
<ReactPlayer
180+
slot="media"
181+
src="https://stream.mux.com/maVbJv2GSYNRgS02kPXOOGdJMWGU1mkA019ZUjYE7VU7k"
182+
controls={false}
183+
style={{
184+
width: "100%",
185+
height: "100%",
186+
"--controls": "none",
187+
}}
188+
></ReactPlayer>
189+
<MediaControlBar>
190+
<MediaPlayButton />
191+
<MediaSeekBackwardButton seekOffset={10} />
192+
<MediaSeekForwardButton seekOffset={10} />
193+
<MediaTimeRange />
194+
<MediaTimeDisplay showDuration />
195+
<MediaMuteButton />
196+
<MediaVolumeRange />
197+
<MediaPlaybackRateButton />
198+
<MediaFullscreenButton />
199+
</MediaControlBar>
200+
</MediaController>
201+
);
202+
}
203+
```
204+
142205
#### Light player
143206

144207
The `light` prop will render a video thumbnail with simple play icon, and only load the full player once a user has interacted with the image. [Noembed](https://noembed.com) is used to fetch thumbnails for a video URL. Note that automatic thumbnail fetching for Facebook, Wistia, Mixcloud and file URLs are not supported, and ongoing support for other URLs is not guaranteed.

0 commit comments

Comments
 (0)