|
|
|
|
@ -12,6 +12,7 @@ import { useFullscreen } from 'features/StreamPlayer/hooks/useFullscreen' |
|
|
|
|
import { useVolume } from 'features/VideoPlayer/hooks/useVolume' |
|
|
|
|
import { useNoNetworkPopupStore } from 'features/NoNetworkPopup' |
|
|
|
|
import { useMatchPageStore } from 'features/MatchPage/store' |
|
|
|
|
import { FULL_GAME_KEY } from 'features/MatchPage/helpers/buildPlaylists' |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
useEventListener, |
|
|
|
|
@ -19,6 +20,7 @@ import { |
|
|
|
|
useObjectState, |
|
|
|
|
usePageParams, |
|
|
|
|
} from 'hooks' |
|
|
|
|
import type { SetPartialState } from 'hooks' |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
MatchInfo, |
|
|
|
|
@ -26,6 +28,8 @@ import { |
|
|
|
|
VIEW_INTERVAL_MS, |
|
|
|
|
} from 'requests' |
|
|
|
|
|
|
|
|
|
import type { PausedData } from 'features/MatchPage/components/FinishedMatch/hooks' |
|
|
|
|
|
|
|
|
|
import { useProgressChangeHandler } from './useProgressChangeHandler' |
|
|
|
|
import { usePlayingHandlers } from './usePlayingHandlers' |
|
|
|
|
import { useVideoQuality } from './useVideoQuality' |
|
|
|
|
@ -57,17 +61,24 @@ export type Props = { |
|
|
|
|
isOpenPopup?: boolean, |
|
|
|
|
onError?: () => void, |
|
|
|
|
onPlayingChange: (playing: boolean) => void, |
|
|
|
|
pausedData: PausedData, |
|
|
|
|
profile: MatchInfo, |
|
|
|
|
setPausedData: SetPartialState<PausedData>, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const useMultiSourcePlayer = ({ |
|
|
|
|
chapters, |
|
|
|
|
onError, |
|
|
|
|
onPlayingChange, |
|
|
|
|
pausedData, |
|
|
|
|
setPausedData, |
|
|
|
|
}: Props) => { |
|
|
|
|
const { |
|
|
|
|
handlePlaylistClick, |
|
|
|
|
isPlayFilterEpisodes, |
|
|
|
|
matchPlaylists, |
|
|
|
|
playNextEpisode, |
|
|
|
|
selectedPlaylist, |
|
|
|
|
setCircleAnimation, |
|
|
|
|
setPlayingProgress, |
|
|
|
|
} = useMatchPageStore() |
|
|
|
|
@ -202,8 +213,39 @@ export const useMultiSourcePlayer = ({ |
|
|
|
|
|
|
|
|
|
setPlayerState({ playedProgress: value }) |
|
|
|
|
setPlayingProgress(Math.floor(value / 1000)) |
|
|
|
|
|
|
|
|
|
if (chapter.isFullMatchChapter) { |
|
|
|
|
setPausedData({ |
|
|
|
|
activeChapterIndex, |
|
|
|
|
activePlayer, |
|
|
|
|
playedProgress: value, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const backToPausedTime = useCallback(() => { |
|
|
|
|
if (selectedPlaylist?.id !== FULL_GAME_KEY) { |
|
|
|
|
handlePlaylistClick(matchPlaylists.match[0]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
setPlayerState((state) => ({ |
|
|
|
|
activeChapterIndex: pausedData.activeChapterIndex, |
|
|
|
|
playedProgress: pausedData.playedProgress, |
|
|
|
|
seek: { |
|
|
|
|
...state.seek, |
|
|
|
|
[pausedData.activePlayer]: pausedData.playedProgress / 1000, |
|
|
|
|
}, |
|
|
|
|
})) |
|
|
|
|
}, 0) |
|
|
|
|
}, [ |
|
|
|
|
selectedPlaylist?.id, |
|
|
|
|
pausedData, |
|
|
|
|
handlePlaylistClick, |
|
|
|
|
matchPlaylists.match, |
|
|
|
|
setPlayerState, |
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
const onEnded = () => { |
|
|
|
|
playNextChapter() |
|
|
|
|
} |
|
|
|
|
@ -248,7 +290,11 @@ export const useMultiSourcePlayer = ({ |
|
|
|
|
playNextEpisode() |
|
|
|
|
} |
|
|
|
|
if (playedProgress >= chapterDuration && !seeking && !isPlayFilterEpisodes) { |
|
|
|
|
playNextChapter() |
|
|
|
|
if (isLastChapterPlaying) { |
|
|
|
|
backToPausedTime() |
|
|
|
|
} else { |
|
|
|
|
playNextChapter() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, [ |
|
|
|
|
isPlayFilterEpisodes, |
|
|
|
|
@ -258,6 +304,8 @@ export const useMultiSourcePlayer = ({ |
|
|
|
|
seeking, |
|
|
|
|
playNextChapter, |
|
|
|
|
setPlayerState, |
|
|
|
|
isLastChapterPlaying, |
|
|
|
|
backToPausedTime, |
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
useEventListener({ |
|
|
|
|
|