mirror of
https://github.com/danog/telegram-tt.git
synced 2024-12-13 17:47:39 +01:00
25 lines
705 B
TypeScript
25 lines
705 B
TypeScript
import { RefObject } from 'react';
|
|
import { useCallback, useRef } from '../lib/teact/teact';
|
|
|
|
import useHeavyAnimationCheck from './useHeavyAnimationCheck';
|
|
import safePlay from '../util/safePlay';
|
|
|
|
export default function useHeavyAnimationCheckForVideo(playerRef: RefObject<HTMLVideoElement>, shouldPlay: boolean) {
|
|
const shouldPlayRef = useRef();
|
|
shouldPlayRef.current = shouldPlay;
|
|
|
|
const pause = useCallback(() => {
|
|
if (playerRef.current) {
|
|
playerRef.current.pause();
|
|
}
|
|
}, [playerRef]);
|
|
|
|
const play = useCallback(() => {
|
|
if (playerRef.current && shouldPlayRef.current) {
|
|
safePlay(playerRef.current);
|
|
}
|
|
}, [playerRef]);
|
|
|
|
useHeavyAnimationCheck(pause, play);
|
|
}
|