parent
7e0f83ad2a
commit
86a9ed498d
@ -1,33 +1,13 @@ |
|||||||
import { RefObject } from 'react' |
|
||||||
|
|
||||||
import findIndex from 'lodash/findIndex' |
import findIndex from 'lodash/findIndex' |
||||||
|
import size from 'lodash/size' |
||||||
|
|
||||||
import type { Chapters } from '../types' |
import type { Chapters } from '../types' |
||||||
|
|
||||||
type Args = { |
export const findChapterByProgress = (chapters: Chapters, progressMs: number) => { |
||||||
from?: number, |
if (size(chapters) === 1 && chapters[0].isFullMatchChapter) return 0 |
||||||
url: string, |
return ( |
||||||
videoRef: RefObject<HTMLVideoElement>, |
|
||||||
} |
|
||||||
|
|
||||||
export const preparePlayer = ({ |
|
||||||
from = 0, |
|
||||||
url, |
|
||||||
videoRef, |
|
||||||
}: Args) => { |
|
||||||
const video = videoRef?.current |
|
||||||
if (!video) return |
|
||||||
|
|
||||||
// eslint-disable-next-line no-param-reassign
|
|
||||||
video.src = url |
|
||||||
if (from) { |
|
||||||
video.currentTime = from |
|
||||||
} |
|
||||||
video.load() |
|
||||||
} |
|
||||||
|
|
||||||
export const findChapterByProgress = (chapters: Chapters, progressMs: number) => ( |
|
||||||
findIndex(chapters, ({ endMs, startMs }) => ( |
findIndex(chapters, ({ endMs, startMs }) => ( |
||||||
startMs <= progressMs && progressMs <= endMs |
startMs <= progressMs && progressMs <= endMs |
||||||
)) |
)) |
||||||
) |
) |
||||||
|
} |
||||||
|
|||||||
Loading…
Reference in new issue