MCPcopy Index your code
hub / github.com/midrender/revideo / Player

Function Player

packages/player-react/src/index.tsx:50–261  ·  view source on GitHub ↗
({
  project,
  controls = true,
  variables = {},
  playing = false,
  currentTime = 0,
  volume = 1,
  looping = true,
  fps = 30,

  width = undefined,
  height = undefined,
  quality = undefined,
  timeDisplayFormat = 'MM:SS',

  onDurationChange = () => {},
  onTimeUpdate = () => {},
  onPlayerReady = () => {},
  onPlayerResize = () => {},
}: PlayerProps)

Source from the content-addressed store, hash-verified

48}
49
50export function Player({
51 project,
52 controls = true,
53 variables = {},
54 playing = false,
55 currentTime = 0,
56 volume = 1,
57 looping = true,
58 fps = 30,
59
60 width = undefined,
61 height = undefined,
62 quality = undefined,
63 timeDisplayFormat = 'MM:SS',
64
65 onDurationChange = () => {},
66 onTimeUpdate = () => {},
67 onPlayerReady = () => {},
68 onPlayerResize = () => {},
69}: PlayerProps) {
70 const [playingState, setPlaying] = useState(playing);
71 const [isMouseOver, setIsMouseOver] = useState(false);
72 const [currentTimeState, setCurrentTime] = useState(currentTime);
73 const [volumeState, setVolumeState] = useState(volume);
74 const [duration, setDuration] = useState(-1);
75
76 const focus = useRef(false);
77 const playerRef = useRef<HTMLDivElement | null>(null);
78 const wrapperRef = useRef<HTMLDivElement | null>(null);
79 const lastRect = useRef<DOMRectReadOnly | null>(null);
80
81 const onClickHandler = controls ? () => setPlaying(prev => !prev) : undefined;
82
83 /**
84 * Sync the playing prop with the player's own state when it changes.
85 */
86 useEffect(() => {
87 setPlaying(playing);
88 }, [playing]);
89
90 /**
91 * Sync the current time with the player's own state.
92 */
93 useEffect(() => {
94 const diff = Math.abs(currentTime - currentTimeState);
95 if (diff > 0.05) {
96 setForcedTime(currentTime);
97 }
98 }, [currentTime]);
99
100 useEffect(() => {
101 setForcedVolume(volume);
102 }, [volume]);
103
104 /**
105 * Receives the current time of the video from the player.
106 */
107 const handleTimeUpdate = (event: Event) => {

Callers

nothing calls this directly

Calls 4

shouldShowControlsFunction · 0.90
setForcedTimeFunction · 0.85
setForcedVolumeFunction · 0.85
setProjectMethod · 0.80

Tested by

no test coverage detected