From e1a7f05f26440ae96e549fc8663ae0a9550474b8 Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Fri, 7 Apr 2023 18:17:07 +0700 Subject: [PATCH] fix(#video-duration): calculate video duration for unfinished video after live --- src/features/MatchPage/components/LiveMatch/helpers.tsx | 8 +++++--- src/features/MatchPage/store/hooks/useMatchData.tsx | 1 + src/features/StreamPlayer/hooks/index.tsx | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/features/MatchPage/components/LiveMatch/helpers.tsx b/src/features/MatchPage/components/LiveMatch/helpers.tsx index 165601ab..49e87366 100644 --- a/src/features/MatchPage/components/LiveMatch/helpers.tsx +++ b/src/features/MatchPage/components/LiveMatch/helpers.tsx @@ -40,11 +40,13 @@ const getFullMatchChapters = ({ ? ((playlist.duration ?? 0) - Number(bound.s)) * 1000 : (playlist.duration ?? 0) * 1000 + const delayedDuration = Math.max(durationMs, Number(bound?.e ?? 0)) * 1000 + return [ { - duration: durationMs, - endMs: durationMs, - endOffsetMs: bound ? Number(bound.e) * 1000 : durationMs, + duration: delayedDuration, + endMs: delayedDuration, + endOffsetMs: delayedDuration, index: 0, isFullMatchChapter: true, startMs: 0, diff --git a/src/features/MatchPage/store/hooks/useMatchData.tsx b/src/features/MatchPage/store/hooks/useMatchData.tsx index 3ec80e74..d81f0e7f 100644 --- a/src/features/MatchPage/store/hooks/useMatchData.tsx +++ b/src/features/MatchPage/store/hooks/useMatchData.tsx @@ -45,6 +45,7 @@ export const useMatchData = (profile: MatchInfo) => { const fullMatchDuration = matchDuration useEffect(() => { if (!profile || (profile.live && Number(profile.c_match_calc_status) <= 1)) return + fetchMatchPlaylists({ fullMatchDuration, id: matchId, diff --git a/src/features/StreamPlayer/hooks/index.tsx b/src/features/StreamPlayer/hooks/index.tsx index 0aebd25a..aafea6ef 100644 --- a/src/features/StreamPlayer/hooks/index.tsx +++ b/src/features/StreamPlayer/hooks/index.tsx @@ -363,8 +363,8 @@ export const useVideoPlayer = ({ }, [isLive, chaptersProps[0].startOffsetMs]) useEffect(() => { - if (((isLive || chapters[0].duration === chaptersProps[0].duration) - && chapters[0]?.endOffsetMs === chaptersProps[0]?.endOffsetMs + if (((isLive || Boolean(Math.round((chapters[0].duration / chaptersProps[0].duration)))) + && Boolean(Math.round(chapters[0]?.endOffsetMs / chaptersProps[0]?.endOffsetMs)) && chapters[0]?.url.match(regURL)?.[0] === chaptersProps[0]?.url.match(regURL)?.[0]) || (isEmpty(chapters) || isEmpty(chaptersProps))) return