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