Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ As of Chrome 66, [videos must be `muted` in order to play automatically](https:/
Prop | Description | Default
---- | ----------- | -------
`src` | The url of a video or song to play | `undefined`
`playing` | Set to `true` or `false` to pause or play the media | `false`
`playing` | Set to `true` or `false` to play or pause the media | `undefined`
`preload` | Applies the `preload` attribute where supported | `undefined`
`playsInline` | Applies the `playsInline` attribute where supported | `false`
`crossOrigin` | Applies the `crossOrigin` attribute where supported | `undefined`
Expand Down
5 changes: 3 additions & 2 deletions src/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ const Player: Player = React.forwardRef((props, ref) => {
useEffect(() => {
if (!playerRef.current) return;

if (playerRef.current.paused && playing) {
// Use strict equality for `playing`, if it's nullish, don't do anything.
if (playerRef.current.paused && playing === true) {
playerRef.current.play();
}
if (!playerRef.current.paused && !playing) {
if (!playerRef.current.paused && playing === false) {
playerRef.current.pause();
}

Expand Down
2 changes: 1 addition & 1 deletion src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const defaultProps: ReactPlayerProps = {
playbackRate: 1,

// custom props
// playing: false,
// playing: undefined,
// pip: false,
// light: false,
// fallback: null,
Expand Down
8 changes: 4 additions & 4 deletions test/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ test('video.load()', async (t) => {

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

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

act(() => {
wrapper.update(<Player ref={videoRef} src="file.mp4" playing activePlayer={HtmlPlayer} />);
wrapper.update(<Player ref={videoRef} src="file.mp4" playing={true} activePlayer={HtmlPlayer} />);
});
await Promise.resolve();

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

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

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

act(() => {
wrapper.update(<Player ref={videoRef} src="file.mp4" activePlayer={HtmlPlayer} />);
wrapper.update(<Player ref={videoRef} src="file.mp4" playing={false} activePlayer={HtmlPlayer} />);
});
await Promise.resolve();

Expand Down