Skip to content

Commit f030463

Browse files
committed
fix: playing prop bug
1 parent a26d253 commit f030463

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ As of Chrome 66, [videos must be `muted` in order to play automatically](https:/
5656
Prop | Description | Default
5757
---- | ----------- | -------
5858
`src` | The url of a video or song to play | `undefined`
59-
`playing` | Set to `true` or `false` to pause or play the media | `false`
59+
`playing` | Set to `true` or `false` to pause or play the media | `undefined`
6060
`preload` | Applies the `preload` attribute where supported | `undefined`
6161
`playsInline` | Applies the `playsInline` attribute where supported | `false`
6262
`crossOrigin` | Applies the `crossOrigin` attribute where supported | `undefined`

src/Player.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ const Player: Player = React.forwardRef((props, ref) => {
1919
useEffect(() => {
2020
if (!playerRef.current) return;
2121

22-
if (playerRef.current.paused && playing) {
22+
// Use strict equality for `playing`, if it's nullish, don't do anything.
23+
if (playerRef.current.paused && playing === true) {
2324
playerRef.current.play();
2425
}
25-
if (!playerRef.current.paused && !playing) {
26+
if (!playerRef.current.paused && playing === false) {
2627
playerRef.current.pause();
2728
}
2829

src/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const defaultProps: ReactPlayerProps = {
2020
playbackRate: 1,
2121

2222
// custom props
23-
// playing: false,
23+
// playing: undefined,
2424
// pip: false,
2525
// light: false,
2626
// fallback: null,

test/Player.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ test('video.load()', async (t) => {
2020

2121
test('video.play()', async (t) => {
2222
const videoRef: React.Ref<HTMLVideoElement> = React.createRef();
23-
const wrapper = render(<Player ref={videoRef} src="file.mp4" activePlayer={HtmlPlayer} />);
23+
const wrapper = render(<Player ref={videoRef} src="file.mp4" playing={false} activePlayer={HtmlPlayer} />);
2424

2525
const play = sinon.fake();
2626
videoRef.current?.addEventListener('play', play);
2727

2828
act(() => {
29-
wrapper.update(<Player ref={videoRef} src="file.mp4" playing activePlayer={HtmlPlayer} />);
29+
wrapper.update(<Player ref={videoRef} src="file.mp4" playing={true} activePlayer={HtmlPlayer} />);
3030
});
3131
await Promise.resolve();
3232

@@ -36,13 +36,13 @@ test('video.play()', async (t) => {
3636

3737
test('video.pause()', async (t) => {
3838
const videoRef: React.Ref<HTMLVideoElement> = React.createRef();
39-
const wrapper = render(<Player ref={videoRef} src="file.mp4" playing activePlayer={HtmlPlayer} />);
39+
const wrapper = render(<Player ref={videoRef} src="file.mp4" playing={true} activePlayer={HtmlPlayer} />);
4040

4141
const pause = sinon.fake();
4242
videoRef.current?.addEventListener('pause', pause);
4343

4444
act(() => {
45-
wrapper.update(<Player ref={videoRef} src="file.mp4" activePlayer={HtmlPlayer} />);
45+
wrapper.update(<Player ref={videoRef} src="file.mp4" playing={false} activePlayer={HtmlPlayer} />);
4646
});
4747
await Promise.resolve();
4848

0 commit comments

Comments
 (0)