move around autoplay effects
This commit is contained in:
@@ -72,25 +72,25 @@ export function Controls({
|
|||||||
}
|
}
|
||||||
}, [interactingViaKeypress])
|
}, [interactingViaKeypress])
|
||||||
|
|
||||||
const autoplayDisabled = useAutoplayDisabled()
|
// pause + unfocus when another video is active
|
||||||
|
|
||||||
// autoplay
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (active && !autoplayDisabled) {
|
if (!active) {
|
||||||
play()
|
|
||||||
}
|
|
||||||
return () => {
|
|
||||||
pause()
|
pause()
|
||||||
setFocused(false)
|
setFocused(false)
|
||||||
}
|
}
|
||||||
}, [active, play, pause, setFocused, autoplayDisabled])
|
}, [active, pause, setFocused])
|
||||||
|
|
||||||
// pause when offscreen
|
// autoplay/pause based on visibility
|
||||||
|
const autoplayDisabled = useAutoplayDisabled()
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!onScreen) {
|
if (active && !autoplayDisabled) {
|
||||||
|
if (onScreen) {
|
||||||
|
play()
|
||||||
|
} else {
|
||||||
pause()
|
pause()
|
||||||
}
|
}
|
||||||
}, [onScreen, pause])
|
}
|
||||||
|
}, [onScreen, pause, active, play, autoplayDisabled])
|
||||||
|
|
||||||
const onPressPlayPause = useCallback(() => {
|
const onPressPlayPause = useCallback(() => {
|
||||||
if (!focused) {
|
if (!focused) {
|
||||||
|
|||||||
Reference in New Issue
Block a user