fix(#1701): resume playedprogress after episode

keep-around/fdb88b04b32b9392e76795099e2ec47c9856b38b
Andrei Dekterev 3 years ago
parent 6e7af920b8
commit 19a360a6f1
  1. 46
      src/features/StreamPlayer/hooks/index.tsx

@ -86,6 +86,8 @@ export const useVideoPlayer = ({
const numberOfChapters = size(chapters) const numberOfChapters = size(chapters)
const { hls, videoRef } = useHlsPlayer(url, resumeFrom) const { hls, videoRef } = useHlsPlayer(url, resumeFrom)
const [isLiveTime, setIsLiveTime] = useState(false) const [isLiveTime, setIsLiveTime] = useState(false)
const [isPausedTime, setIsPausedTime] = useState(false)
const [pausedProgress, setPausedProgress] = useState(0)
const chaptersDuration = useDuration(chapters) const chaptersDuration = useDuration(chapters)
@ -227,6 +229,38 @@ export const useVideoPlayer = ({
setPlayerState, 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(() => { useEffect(() => {
if (duration && isLiveTime && chapters[0]?.isFullMatchChapter) { if (duration && isLiveTime && chapters[0]?.isFullMatchChapter) {
backToLive() backToLive()
@ -234,6 +268,13 @@ export const useVideoPlayer = ({
// eslint-disable-next-line // eslint-disable-next-line
}, [duration, isLiveTime]) }, [duration, isLiveTime])
useEffect(() => {
if (duration && isPausedTime && chapters[0]?.isFullMatchChapter) {
backToPausedTime()
}
// eslint-disable-next-line
}, [duration, isPausedTime])
useEventListener({ useEventListener({
callback: (e: KeyboardEvent) => { callback: (e: KeyboardEvent) => {
if (e.code === 'ArrowLeft') rewindBackward() if (e.code === 'ArrowLeft') rewindBackward()
@ -275,8 +316,13 @@ export const useVideoPlayer = ({
const { duration: chapterDuration } = getActiveChapter() const { duration: chapterDuration } = getActiveChapter()
if (playedProgress >= chapterDuration && !seeking) { if (playedProgress >= chapterDuration && !seeking) {
if (isLive) {
backToPausedTime()
} else {
playNextChapter() playNextChapter()
} }
}
// eslint-disable-next-line
}, [ }, [
isLive, isLive,
chapters, chapters,

Loading…
Cancel
Save