|
|
|
|
@ -16,6 +16,7 @@ import { useEventListener } from 'hooks/useEventListener' |
|
|
|
|
|
|
|
|
|
import { useVolume } from 'features/VideoPlayer/hooks/useVolume' |
|
|
|
|
import { useNoNetworkPopupStore } from 'features/NoNetworkPopup' |
|
|
|
|
import { useLiveMatch } from 'features/MatchPage/components/LiveMatch/hooks' |
|
|
|
|
|
|
|
|
|
import type { Chapters } from 'features/StreamPlayer/types' |
|
|
|
|
|
|
|
|
|
@ -79,6 +80,9 @@ export const useVideoPlayer = ({ |
|
|
|
|
seeking, |
|
|
|
|
}, setPlayerState] = useObjectState({ ...initialState, chapters: chaptersProps }) |
|
|
|
|
|
|
|
|
|
const { onPlaylistSelect, selectedPlaylist } = useLiveMatch() |
|
|
|
|
const [pauseTime, setPauseTime] = useState(0) |
|
|
|
|
|
|
|
|
|
const { url } = chapters[0] ?? { url: '' } |
|
|
|
|
const numberOfChapters = size(chapters) |
|
|
|
|
const { hls, videoRef } = useHlsPlayer(url, resumeFrom) |
|
|
|
|
@ -96,6 +100,7 @@ export const useVideoPlayer = ({ |
|
|
|
|
stopPlaying, |
|
|
|
|
togglePlaying, |
|
|
|
|
} = usePlayingHandlers(setPlayerState, chapters) |
|
|
|
|
console.log('playedProgress', playedProgress, '|', 'chapters =', chapters) |
|
|
|
|
|
|
|
|
|
const getActiveChapter = useCallback( |
|
|
|
|
(index: number = activeChapterIndex) => chapters[index], |
|
|
|
|
@ -232,21 +237,45 @@ export const useVideoPlayer = ({ |
|
|
|
|
...initialState, |
|
|
|
|
chapters: chaptersProps, |
|
|
|
|
playing: true, |
|
|
|
|
seek: chaptersProps[0].startOffsetMs / 1000, |
|
|
|
|
seek: (pauseTime || chaptersProps[0].startOffsetMs) / 1000, |
|
|
|
|
}) |
|
|
|
|
}, [ |
|
|
|
|
chapters, |
|
|
|
|
chaptersProps, |
|
|
|
|
isLive, |
|
|
|
|
setPlayerState, |
|
|
|
|
pauseTime, |
|
|
|
|
]) |
|
|
|
|
console.log('pauseTime', pauseTime, '\n', 'chapters', chapters, '\n', 'playedProgress', playedProgress, '\n', 'selectedPlaylist', selectedPlaylist) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (!isLive) return |
|
|
|
|
if (isLive && selectedPlaylist?.id !== 'full_game') { |
|
|
|
|
// setPauseTime(playedProgress)
|
|
|
|
|
} |
|
|
|
|
}, [selectedPlaylist]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if ((isLive && chapters[0]?.isFullMatchChapter) || isEmpty(chapters)) return |
|
|
|
|
|
|
|
|
|
const { duration: chapterDuration } = getActiveChapter() |
|
|
|
|
if (playedProgress >= chapterDuration && !seeking) { |
|
|
|
|
if (playedProgress >= chapterDuration && !seeking && !isLive) { |
|
|
|
|
playNextChapter() |
|
|
|
|
} else if (playedProgress >= chapterDuration && !seeking && isLive) { |
|
|
|
|
onPlaylistSelect({ |
|
|
|
|
duration: 0, |
|
|
|
|
episodes: [], |
|
|
|
|
id: 'full_game', |
|
|
|
|
lexic: 13028, |
|
|
|
|
type: 0, |
|
|
|
|
}) |
|
|
|
|
console.log('newChapters', chapters) |
|
|
|
|
seekTo(pauseTime) |
|
|
|
|
// setPlayerState({
|
|
|
|
|
// ...initialState,
|
|
|
|
|
// chapters: chaptersProps,
|
|
|
|
|
// seek: pauseTime / 1000,
|
|
|
|
|
// })
|
|
|
|
|
} |
|
|
|
|
}, [ |
|
|
|
|
isLive, |
|
|
|
|
|