try and guard play/pause against unmount
This commit is contained in:
@@ -1044,16 +1044,25 @@ function PlayPauseTapArea({
|
|||||||
const {isPlaying} = useEvent(player, 'playingChange', {
|
const {isPlaying} = useEvent(player, 'playingChange', {
|
||||||
isPlaying: player.playing,
|
isPlaying: player.playing,
|
||||||
})
|
})
|
||||||
|
const isMounted = useRef(false)
|
||||||
|
|
||||||
const togglePlayPause = () => {
|
useEffect(() => {
|
||||||
if (!player) return
|
isMounted.current = true
|
||||||
|
return () => {
|
||||||
|
isMounted.current = false
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const togglePlayPause = useNonReactiveCallback(() => {
|
||||||
|
// gets called after a timeout, so guard against being called after unmount -sfn
|
||||||
|
if (!player || !isMounted.current) return
|
||||||
doubleTapRef.current = null
|
doubleTapRef.current = null
|
||||||
if (player.playing) {
|
if (player.playing) {
|
||||||
player.pause()
|
player.pause()
|
||||||
} else {
|
} else {
|
||||||
player.play()
|
player.play()
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
const onPress = () => {
|
const onPress = () => {
|
||||||
if (doubleTapRef.current) {
|
if (doubleTapRef.current) {
|
||||||
|
|||||||
Reference in New Issue
Block a user