parent
7e0f83ad2a
commit
86a9ed498d
@ -1,33 +1,13 @@ |
||||
import { RefObject } from 'react' |
||||
|
||||
import findIndex from 'lodash/findIndex' |
||||
import size from 'lodash/size' |
||||
|
||||
import type { Chapters } from '../types' |
||||
|
||||
type Args = { |
||||
from?: number, |
||||
url: string, |
||||
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) => ( |
||||
export const findChapterByProgress = (chapters: Chapters, progressMs: number) => { |
||||
if (size(chapters) === 1 && chapters[0].isFullMatchChapter) return 0 |
||||
return ( |
||||
findIndex(chapters, ({ endMs, startMs }) => ( |
||||
startMs <= progressMs && progressMs <= endMs |
||||
)) |
||||
) |
||||
) |
||||
} |
||||
|
||||
Loading…
Reference in new issue