Skip to content

Commit

Permalink
Switch to paused rather than playing to control videos
Browse files Browse the repository at this point in the history
  • Loading branch information
weotch committed Sep 22, 2023
1 parent 605d75c commit 7127360
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/next/src/NextVisual.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function NextVisual(
priority,
sizes,
imageLoader,
playing,
paused,
alt,
className = '',
style = {},
Expand Down Expand Up @@ -69,7 +69,7 @@ export default function NextVisual(
position,
priority,
noPoster: !!image, // Use `image` as poster frame
playing,
paused,
}} /> }

</VisualWrapper>
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/types/nextVisualTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type NextVisualProps = {
sizes?: string
imageLoader?: Function

playing?: boolean
paused?: boolean

alt: string

Expand Down
8 changes: 4 additions & 4 deletions packages/react/cypress/component/LazyVideo.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { LazyVideo } from '../../src'
// Make an instance of LazyVideo that can be controlled
const Player = function({ autoplay }: any) {

const [playing, setPlaying] = useState(autoplay)
const [paused, setPaused] = useState(!autoplay)

return (<>
<LazyVideo
src='https://placehold.co/300x200.mp4'
alt=''
playing={ playing }/>
paused={ paused }/>
<div style={{ position: 'relative' }}>
<button onClick={() => setPlaying(true)}>Play</button>
<button onClick={() => setPlaying(false)}>Pause</button>
<button onClick={() => setPaused(false)}>Play</button>
<button onClick={() => setPaused(true)}>Pause</button>
</div>
</>)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Cypress.Commands.add('isPlaying',
cy.wrap(subject).should('have.prop', 'paused', false)
})

// Check that a video is playing
// Check that a video is paused
// https://glebbahmutov.com/blog/test-video-play/
Cypress.Commands.add('isPaused',
{ prevSubject: true },
Expand Down
10 changes: 5 additions & 5 deletions packages/react/src/LazyVideo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { fillStyles, transparentGif } from './lib/styles'

// An video rendered within a Visual that supports lazy loading
export default function LazyVideo({
src, alt, fit, position, priority, noPoster, playing = true
src, alt, fit, position, priority, noPoster, paused
}: LazyVideoProps): ReactElement {

// Make a ref to the video so it can be controlled
Expand Down Expand Up @@ -45,10 +45,10 @@ export default function LazyVideo({
videoRef.current?.pause()
}

// Respond to playing prop and call methods that control the video playback
// Respond to paused prop and call methods that control the video playback
useEffect(() => {
playing ? play() : pause()
}, [ playing ])
paused ? pause() : play()
}, [ paused ])

// Simplify logic for whether to load sources
const shouldLoad = priority || inView
Expand All @@ -62,7 +62,7 @@ export default function LazyVideo({
loop

// Whether to autoplay
autoPlay={ playing }
autoPlay={ !paused }

// Load a transparent gif as a poster if an `image` was specified so
// the image is used as poster rather than the first frame of video. This
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/types/lazyVideoTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export type LazyVideoProps = {
// Use a transparent gif poster image
noPoster?: boolean

// Controls autoplaying and current playing state
playing?: boolean
// Controls autoplaying and play state
paused?: boolean

// Display props
fit?: CSSProperties['objectFit']
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity-next/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Cypress.Commands.add('hasDimensions',
return subject
})

// Check that a video is playing
// Check that a video is paused
// https://glebbahmutov.com/blog/test-video-play/
Cypress.Commands.add('isPlaying',
{ prevSubject: true },
Expand Down

0 comments on commit 7127360

Please sign in to comment.