[Video] Disable autoplay option (preview + web player) (#5167)

* rename setting

* preview (web)

* preview (native)

* improve autoplay disabled behaviour on web
This commit is contained in:
Samuel Newman 2024-09-05 15:56:10 +01:00 committed by GitHub
parent d846f5bbf0
commit 60b74f7ab8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 8 deletions

View file

@ -111,9 +111,9 @@ export function Controls({
// autoplay/pause based on visibility
const autoplayDisabled = useAutoplayDisabled()
useEffect(() => {
if (active && !autoplayDisabled) {
if (active) {
if (onScreen) {
play()
if (!autoplayDisabled) play()
} else {
pause()
}
@ -151,10 +151,11 @@ export function Controls({
const onPressEmptySpace = useCallback(() => {
if (!focused) {
drawFocus()
if (autoplayDisabled) play()
} else {
togglePlayPause()
}
}, [togglePlayPause, drawFocus, focused])
}, [togglePlayPause, drawFocus, focused, autoplayDisabled, play])
const onPressPlayPause = useCallback(() => {
drawFocus()
@ -240,7 +241,8 @@ export function Controls({
}, [])
const showControls =
(focused && !playing) || (interactingViaKeypress ? hasFocus : hovered)
((focused || autoplayDisabled) && !playing) ||
(interactingViaKeypress ? hasFocus : hovered)
return (
<div
@ -273,7 +275,10 @@ export function Controls({
? msg`Pause video`
: msg`Play video`,
)}
style={[a.flex_1, web({cursor: showCursor ? 'pointer' : 'none'})]}
style={[
a.flex_1,
web({cursor: showCursor || !playing ? 'pointer' : 'none'}),
]}
onPress={onPressEmptySpace}
/>
{!showControls && !focused && duration > 0 && (