[Video] Try/catch video play/pause (#4930)
Co-authored-by: Samuel Newman <10959775+mozzius@users.noreply.github.com>
This commit is contained in:
parent
57be2ea15b
commit
630ebf523d
2 changed files with 21 additions and 7 deletions
|
|
@ -8,6 +8,7 @@ import {useIsFocused} from '@react-navigation/native'
|
|||
|
||||
import {HITSLOP_30} from '#/lib/constants'
|
||||
import {useAppState} from '#/lib/hooks/useAppState'
|
||||
import {logger} from '#/logger'
|
||||
import {useVideoPlayer} from '#/view/com/util/post-embeds/VideoPlayerContext'
|
||||
import {android, atoms as a, useTheme} from '#/alf'
|
||||
import {Mute_Stroke2_Corner0_Rounded as MuteIcon} from '#/components/icons/Mute'
|
||||
|
|
@ -25,10 +26,17 @@ export function VideoEmbedInnerNative() {
|
|||
const isAppFocused = useAppState()
|
||||
|
||||
useEffect(() => {
|
||||
if (isAppFocused === 'active' && isScreenFocused && !player.playing) {
|
||||
player.play()
|
||||
} else if (player.playing) {
|
||||
player.pause()
|
||||
try {
|
||||
if (isAppFocused === 'active' && isScreenFocused && !player.playing) {
|
||||
player.play()
|
||||
} else if (player.playing) {
|
||||
player.pause()
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(
|
||||
'Failed to play/pause while backgrounding/switching screens',
|
||||
{safeMessage: err},
|
||||
)
|
||||
}
|
||||
}, [isAppFocused, player, isScreenFocused])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue