diff --git a/src/features/StreamPlayer/hooks/index.tsx b/src/features/StreamPlayer/hooks/index.tsx index c625847d..3a06ec9b 100644 --- a/src/features/StreamPlayer/hooks/index.tsx +++ b/src/features/StreamPlayer/hooks/index.tsx @@ -86,6 +86,8 @@ export const useVideoPlayer = ({ const numberOfChapters = size(chapters) const { hls, videoRef } = useHlsPlayer(url, resumeFrom) const [isLiveTime, setIsLiveTime] = useState(false) + const [isPausedTime, setIsPausedTime] = useState(false) + const [pausedProgress, setPausedProgress] = useState(0) const chaptersDuration = useDuration(chapters) @@ -227,6 +229,38 @@ export const useVideoPlayer = ({ setPlayerState, ]) + const backToPausedTime = useCallback(() => { + if (!duration) return + + if (selectedPlaylist?.id !== 'full_game') { + onPlaylistSelect({ + duration: 0, + episodes: [], + id: 'full_game', + lexic: 13028, + type: 0, + }) + setIsPausedTime(true) + } + + const liveProgressMs = Math.max(duration - 30000, 0) + setPlayerState({ playedProgress: pausedProgress, seek: pausedProgress / 1000 }) + if (liveProgressMs > 0) setIsPausedTime(false) + // eslint-disable-next-line + }, [ + duration, + onPlaylistSelect, + selectedPlaylist, + setPlayerState, + ]) + + useEffect(() => { + if (chapters[0]?.isFullMatchChapter) { + setPausedProgress(playedProgress) + } + // eslint-disable-next-line + }, [selectedPlaylist]) + useEffect(() => { if (duration && isLiveTime && chapters[0]?.isFullMatchChapter) { backToLive() @@ -234,6 +268,13 @@ export const useVideoPlayer = ({ // eslint-disable-next-line }, [duration, isLiveTime]) + useEffect(() => { + if (duration && isPausedTime && chapters[0]?.isFullMatchChapter) { + backToPausedTime() + } + // eslint-disable-next-line + }, [duration, isPausedTime]) + useEventListener({ callback: (e: KeyboardEvent) => { if (e.code === 'ArrowLeft') rewindBackward() @@ -275,8 +316,13 @@ export const useVideoPlayer = ({ const { duration: chapterDuration } = getActiveChapter() if (playedProgress >= chapterDuration && !seeking) { - playNextChapter() + if (isLive) { + backToPausedTime() + } else { + playNextChapter() + } } + // eslint-disable-next-line }, [ isLive, chapters,