|
|
|
@ -1,6 +1,7 @@ |
|
|
|
import throttle from "lodash.throttle"; |
|
|
|
import throttle from "lodash.throttle"; |
|
|
|
import { useEffect, useMemo, useRef } from "react"; |
|
|
|
import { useEffect, useMemo, useRef } from "react"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { useQueryParams } from "@/hooks/useQueryParams"; |
|
|
|
import { useVideoPlayerDescriptor } from "@/video/state/hooks"; |
|
|
|
import { useVideoPlayerDescriptor } from "@/video/state/hooks"; |
|
|
|
import { useControls } from "@/video/state/logic/controls"; |
|
|
|
import { useControls } from "@/video/state/logic/controls"; |
|
|
|
import { useMediaPlaying } from "@/video/state/logic/mediaplaying"; |
|
|
|
import { useMediaPlaying } from "@/video/state/logic/mediaplaying"; |
|
|
|
@ -20,6 +21,7 @@ export function ProgressListenerController(props: Props) { |
|
|
|
const misc = useMisc(descriptor); |
|
|
|
const misc = useMisc(descriptor); |
|
|
|
const didInitialize = useRef<true | null>(null); |
|
|
|
const didInitialize = useRef<true | null>(null); |
|
|
|
const lastTime = useRef<number>(props.startAt ?? 0); |
|
|
|
const lastTime = useRef<number>(props.startAt ?? 0); |
|
|
|
|
|
|
|
const queryParams = useQueryParams(); |
|
|
|
|
|
|
|
|
|
|
|
// time updates (throttled)
|
|
|
|
// time updates (throttled)
|
|
|
|
const updateTime = useMemo( |
|
|
|
const updateTime = useMemo( |
|
|
|
@ -56,9 +58,28 @@ export function ProgressListenerController(props: Props) { |
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (lastStateProviderId.current === stateProviderId) return; |
|
|
|
if (lastStateProviderId.current === stateProviderId) return; |
|
|
|
if (mediaPlaying.isFirstLoading) return; |
|
|
|
if (mediaPlaying.isFirstLoading) return; |
|
|
|
|
|
|
|
|
|
|
|
lastStateProviderId.current = stateProviderId; |
|
|
|
lastStateProviderId.current = stateProviderId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((queryParams.t ?? null) !== null) { |
|
|
|
|
|
|
|
// Convert `t` param to time. Supports only seconds, but also `3:30` or `1:30:02`
|
|
|
|
|
|
|
|
const timeArr = queryParams.t.toString().split(":").map(Number); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const hours = timeArr[timeArr.length - 3] ?? 0; |
|
|
|
|
|
|
|
const minutes = Math.min(timeArr[timeArr.length - 2] ?? 0, 59); |
|
|
|
|
|
|
|
const seconds = Math.min( |
|
|
|
|
|
|
|
timeArr[timeArr.length - 1] ?? 0, |
|
|
|
|
|
|
|
minutes > 0 ? 59 : Infinity |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
console.log(hours, minutes, seconds, 123); |
|
|
|
|
|
|
|
const timeInSeconds = hours * 60 * 60 + minutes * 60 + seconds; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
controls.setTime(timeInSeconds); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
controls.setTime(lastTime.current); |
|
|
|
controls.setTime(lastTime.current); |
|
|
|
}, [controls, mediaPlaying, stateProviderId]); |
|
|
|
}, [controls, mediaPlaying, stateProviderId, queryParams]); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
// if it initialized, but media starts loading for the first time again.
|
|
|
|
// if it initialized, but media starts loading for the first time again.
|
|
|
|
|