fix(#1701): fix button live for live stream from episodes

keep-around/fdb88b04b32b9392e76795099e2ec47c9856b38b
Andrei Dekterev 4 years ago
parent 1a4896f95d
commit 6e7af920b8
  1. 61
      src/features/StreamPlayer/hooks/index.tsx

@ -81,11 +81,11 @@ export const useVideoPlayer = ({
}, 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)
const [isLiveTime, setIsLiveTime] = useState(false)
const chaptersDuration = useDuration(chapters)
@ -100,7 +100,6 @@ export const useVideoPlayer = ({
stopPlaying,
togglePlaying,
} = usePlayingHandlers(setPlayerState, chapters)
console.log('playedProgress', playedProgress, '|', 'chapters =', chapters)
const getActiveChapter = useCallback(
(index: number = activeChapterIndex) => chapters[index],
@ -205,10 +204,35 @@ export const useVideoPlayer = ({
}
const backToLive = useCallback(() => {
const liveProgressMs = Math.max(duration - 30000, 0)
if (!duration) return
if (selectedPlaylist?.id !== 'full_game') {
onPlaylistSelect({
duration: 0,
episodes: [],
id: 'full_game',
lexic: 13028,
type: 0,
})
setIsLiveTime(true)
}
const liveProgressMs = Math.max(duration - 30000, 0)
setPlayerState({ playedProgress: liveProgressMs, seek: liveProgressMs / 1000 })
}, [duration, setPlayerState])
if (liveProgressMs > 0) setIsLiveTime(false)
}, [
duration,
onPlaylistSelect,
selectedPlaylist,
setPlayerState,
])
useEffect(() => {
if (duration && isLiveTime && chapters[0]?.isFullMatchChapter) {
backToLive()
}
// eslint-disable-next-line
}, [duration, isLiveTime])
useEventListener({
callback: (e: KeyboardEvent) => {
@ -237,50 +261,27 @@ export const useVideoPlayer = ({
...initialState,
chapters: chaptersProps,
playing: true,
seek: (pauseTime || chaptersProps[0].startOffsetMs) / 1000,
seek: 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 && !isLive) {
if (playedProgress >= chapterDuration && !seeking) {
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,
chapters,
getActiveChapter,
onPlaylistSelect,
playedProgress,
seeking,
playNextChapter,

Loading…
Cancel
Save