fix(#1701): stop back to start video after episodes

keep-around/fdb88b04b32b9392e76795099e2ec47c9856b38b
Andrei Dekterev 3 years ago
parent 19a360a6f1
commit cd0a0be6e3
  1. 41
      src/features/StreamPlayer/components/Chapters/index.tsx
  2. 3
      src/features/StreamPlayer/components/ProgressBar/hooks.tsx
  3. 4
      src/features/StreamPlayer/components/ProgressBar/index.tsx
  4. 5
      src/features/StreamPlayer/hooks/index.tsx
  5. 1
      src/features/StreamPlayer/index.tsx

@ -1,3 +1,5 @@
import { RefObject } from 'react'
import map from 'lodash/map' import map from 'lodash/map'
import type { Chapter } from '../../types' import type { Chapter } from '../../types'
@ -16,24 +18,25 @@ type ChapterWithStyles = Chapter & {
type Props = { type Props = {
chapters: Array<ChapterWithStyles>, chapters: Array<ChapterWithStyles>,
videoRef?: RefObject<HTMLVideoElement>,
} }
export const Chapters = ({ chapters }: Props) => ( export const Chapters = ({ chapters, videoRef }: Props) => {
<ChapterList> const maxWidthProgressBar = videoRef?.current?.offsetWidth
{ return (
map( <ChapterList>
chapters, {map(chapters, ({
({ loaded,
loaded, played,
played, width,
width, }, index) => (
}, index) => ( <ChapterContainer key={index} style={{ width: `${width}%` }}>
<ChapterContainer key={index} style={{ width: `${width}%` }}> <LoadedProgress style={{ width: `${loaded}%` }} />
<LoadedProgress style={{ width: `${loaded}%` }} /> <PlayedProgress
<PlayedProgress style={{ width: `${played}%` }} /> style={{ maxWidth: `${maxWidthProgressBar ? `${maxWidthProgressBar - 30}px` : '100%'}`, width: `${played}%` }}
</ChapterContainer> />
), </ChapterContainer>
) ))}
} </ChapterList>
</ChapterList> )
) }

@ -1,4 +1,4 @@
import { useMemo } from 'react' import { useMemo, RefObject } from 'react'
import { secondsToHms } from 'helpers' import { secondsToHms } from 'helpers'
@ -15,6 +15,7 @@ export type Props = {
onTouchEnd?: () => any, onTouchEnd?: () => any,
onTouchStart?: () => any, onTouchStart?: () => any,
playedProgress: number, playedProgress: number,
videoRef?: RefObject<HTMLVideoElement>,
} }
export const useProgressBar = ({ export const useProgressBar = ({

@ -8,7 +8,7 @@ import { useProgressBar } from './hooks'
import { ProgressBarList } from './styled' import { ProgressBarList } from './styled'
export const ProgressBar = (props: Props) => { export const ProgressBar = (props: Props) => {
const { onPlayedProgressChange } = props const { onPlayedProgressChange, videoRef } = props
const progressBarRef = useSlider({ onChange: onPlayedProgressChange }) const progressBarRef = useSlider({ onChange: onPlayedProgressChange })
const { const {
calculatedChapters, calculatedChapters,
@ -18,7 +18,7 @@ export const ProgressBar = (props: Props) => {
return ( return (
<ProgressBarList ref={progressBarRef}> <ProgressBarList ref={progressBarRef}>
<Chapters chapters={calculatedChapters} /> <Chapters chapters={calculatedChapters} videoRef={videoRef} />
<Scrubber style={{ left: `${playedProgressInPercent}%` }}> <Scrubber style={{ left: `${playedProgressInPercent}%` }}>
<TimeTooltip time={time} /> <TimeTooltip time={time} />
</Scrubber> </Scrubber>

@ -298,6 +298,11 @@ export const useVideoPlayer = ({
}, [playing, onPlayingChange]) }, [playing, onPlayingChange])
useEffect(() => { useEffect(() => {
if ((isLive
&& chapters[0]?.isFullMatchChapter
&& chaptersProps[0]?.isFullMatchChapter)
|| isEmpty(chapters)) return
setPlayerState({ setPlayerState({
...initialState, ...initialState,
chapters: chaptersProps, chapters: chaptersProps,

@ -153,6 +153,7 @@ export const StreamPlayer = (props: Props) => {
onPlayedProgressChange={onProgressChange} onPlayedProgressChange={onProgressChange}
playedProgress={playedProgress} playedProgress={playedProgress}
loadedProgress={loadedProgress} loadedProgress={loadedProgress}
videoRef={videoRef}
/> />
</ControlsRow> </ControlsRow>
<ControlsRow> <ControlsRow>

Loading…
Cancel
Save