Revert "Adjust logic to only run interval when video is playing."

This reverts commit 5ce6ab9689c1610f24869c7347b823cc2023b767.
This commit is contained in:
David Granado 2022-03-02 22:12:11 -06:00 committed by infinite-persistence
parent 3631bdddbc
commit 7263bde491

View file

@ -127,7 +127,6 @@ function VideoViewer(props: Props) {
const [ended, setEnded] = useState(false); const [ended, setEnded] = useState(false);
const [showAutoplayCountdown, setShowAutoplayCountdown] = useState(false); const [showAutoplayCountdown, setShowAutoplayCountdown] = useState(false);
const [isEndedEmbed, setIsEndedEmbed] = useState(false); const [isEndedEmbed, setIsEndedEmbed] = useState(false);
const [playerObj, setPlayerObj] = useState(null);
const vjsCallbackDataRef: any = React.useRef(); const vjsCallbackDataRef: any = React.useRef();
const previousUri = usePrevious(uri); const previousUri = usePrevious(uri);
const embedded = useContext(EmbedContext); const embedded = useContext(EmbedContext);
@ -140,7 +139,7 @@ function VideoViewer(props: Props) {
const [videoNode, setVideoNode] = useState(); const [videoNode, setVideoNode] = useState();
const [localAutoplayNext, setLocalAutoplayNext] = useState(autoplayNext); const [localAutoplayNext, setLocalAutoplayNext] = useState(autoplayNext);
const isFirstRender = React.useRef(true); const isFirstRender = React.useRef(true);
const savePositionInterval = isPlaying ? PLAY_POSITION_SAVE_INTERVAL_MS : null; const playerRef = React.useRef(null);
useEffect(() => { useEffect(() => {
if (isFirstRender.current) { if (isFirstRender.current) {
@ -151,10 +150,10 @@ function VideoViewer(props: Props) {
}, [localAutoplayNext]); }, [localAutoplayNext]);
useInterval(() => { useInterval(() => {
if (playerObj) { if (playerRef.current && isPlaying) {
handlePosition(playerObj); handlePosition(playerRef.current);
} }
}, savePositionInterval); }, PLAY_POSITION_SAVE_INTERVAL_MS);
const updateVolumeState = React.useCallback( const updateVolumeState = React.useCallback(
debounce((volume, muted) => { debounce((volume, muted) => {
@ -431,7 +430,7 @@ function VideoViewer(props: Props) {
player.currentTime(position); player.currentTime(position);
} }
setPlayerObj(player); playerRef.current = player;
}, playerReadyDependencyList); // eslint-disable-line }, playerReadyDependencyList); // eslint-disable-line
return ( return (