refactor(1701): stream player (#558)
parent
950a02c7ae
commit
d3b25de38d
@ -1,14 +1,11 @@ |
|||||||
import map from 'lodash/map' |
import map from 'lodash/map' |
||||||
|
|
||||||
import { |
|
||||||
LoadedProgress, |
|
||||||
PlayedProgress, |
|
||||||
} from 'features/StreamPlayer/components/ProgressBar/styled' |
|
||||||
|
|
||||||
import type { Chapter } from '../../types' |
import type { Chapter } from '../../types' |
||||||
import { |
import { |
||||||
ChapterList, |
ChapterList, |
||||||
ChapterContainer, |
ChapterContainer, |
||||||
|
LoadedProgress, |
||||||
|
PlayedProgress, |
||||||
} from './styled' |
} from './styled' |
||||||
|
|
||||||
type ChapterWithStyles = Chapter & { |
type ChapterWithStyles = Chapter & { |
||||||
@ -1,43 +1,27 @@ |
|||||||
import { secondsToHms } from 'helpers' |
|
||||||
|
|
||||||
import { useSlider } from 'features/StreamPlayer/hooks/useSlider' |
import { useSlider } from 'features/StreamPlayer/hooks/useSlider' |
||||||
import { TimeTooltip } from 'features/StreamPlayer/components/TimeTooltip' |
import { TimeTooltip } from 'features/StreamPlayer/components/TimeTooltip' |
||||||
|
import { Scrubber } from 'features/StreamPlayer/components/ProgressBar/styled' |
||||||
|
|
||||||
import { |
import { Chapters } from '../Chapters' |
||||||
ProgressBarList, |
import type { Props } from './hooks' |
||||||
LoadedProgress, |
import { useProgressBar } from './hooks' |
||||||
PlayedProgress, |
import { ProgressBarList } from './styled' |
||||||
Scrubber, |
|
||||||
} from './styled' |
|
||||||
|
|
||||||
type Props = { |
|
||||||
duration: number, |
|
||||||
isScrubberVisible?: boolean, |
|
||||||
loadedProgress: number, |
|
||||||
onPlayedProgressChange: (progress: number) => void, |
|
||||||
playedProgress: number, |
|
||||||
} |
|
||||||
|
|
||||||
export const ProgressBar = ({ |
export const ProgressBar = (props: Props) => { |
||||||
duration, |
const { onPlayedProgressChange } = props |
||||||
isScrubberVisible, |
|
||||||
loadedProgress, |
|
||||||
onPlayedProgressChange, |
|
||||||
playedProgress, |
|
||||||
}: Props) => { |
|
||||||
const progressBarRef = useSlider({ onChange: onPlayedProgressChange }) |
const progressBarRef = useSlider({ onChange: onPlayedProgressChange }) |
||||||
const loadedFraction = Math.min(loadedProgress * 100 / duration, 100) |
const { |
||||||
const playedFraction = Math.min(playedProgress * 100 / duration, 100) |
calculatedChapters, |
||||||
|
playedProgressInPercent, |
||||||
|
time, |
||||||
|
} = useProgressBar(props) |
||||||
|
|
||||||
return ( |
return ( |
||||||
<ProgressBarList ref={progressBarRef}> |
<ProgressBarList ref={progressBarRef}> |
||||||
<LoadedProgress style={{ width: `${loadedFraction}%` }} /> |
<Chapters chapters={calculatedChapters} /> |
||||||
<PlayedProgress style={{ width: `${playedFraction}%` }} /> |
<Scrubber style={{ left: `${playedProgressInPercent}%` }}> |
||||||
{isScrubberVisible === false ? null : ( |
<TimeTooltip time={time} /> |
||||||
<Scrubber style={{ left: `${playedFraction}%` }}> |
</Scrubber> |
||||||
<TimeTooltip time={secondsToHms(playedProgress / 1000)} /> |
|
||||||
</Scrubber> |
|
||||||
)} |
|
||||||
</ProgressBarList> |
</ProgressBarList> |
||||||
) |
) |
||||||
} |
} |
||||||
|
|||||||
@ -1,18 +1,11 @@ |
|||||||
export type Urls = { [quality: string]: string } |
|
||||||
|
|
||||||
export type Chapter = { |
export type Chapter = { |
||||||
duration: number, |
duration: number, |
||||||
endMs: number, |
endMs: number, |
||||||
endOffsetMs: number, |
endOffsetMs: number, |
||||||
period: number, |
index?: number, |
||||||
startMs: number, |
startMs: number, |
||||||
startOffsetMs: number, |
startOffsetMs: number, |
||||||
urls: Urls, |
url: string, |
||||||
} |
} |
||||||
|
|
||||||
export type Chapters = Array<Chapter> |
export type Chapters = Array<Chapter> |
||||||
|
|
||||||
export enum Players { |
|
||||||
PLAYER1 = 0, |
|
||||||
PLAYER2 = 1, |
|
||||||
} |
|
||||||
Loading…
Reference in new issue