|
|
|
|
@ -55,6 +55,7 @@ export const useMultiSourcePlayer = ({ |
|
|
|
|
onProgressChange: onProgressChangeCallback, |
|
|
|
|
resumeFrom, |
|
|
|
|
}: Props) => { |
|
|
|
|
const numberOfChapters = size(chapters) |
|
|
|
|
const [ |
|
|
|
|
{ |
|
|
|
|
activeChapterIndex, |
|
|
|
|
@ -69,10 +70,12 @@ export const useMultiSourcePlayer = ({ |
|
|
|
|
const videoRef = useRef<HTMLVideoElement>(null) |
|
|
|
|
const { |
|
|
|
|
onReady, |
|
|
|
|
playNextChapter, |
|
|
|
|
playPrevChapter, |
|
|
|
|
startPlaying, |
|
|
|
|
stopPlaying, |
|
|
|
|
togglePlaying, |
|
|
|
|
} = usePlayingHandlers(setPlayerState) |
|
|
|
|
} = usePlayingHandlers(setPlayerState, numberOfChapters) |
|
|
|
|
|
|
|
|
|
const { |
|
|
|
|
selectedQuality, |
|
|
|
|
@ -105,16 +108,6 @@ export const useMultiSourcePlayer = ({ |
|
|
|
|
setSelectedQuality(quality) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const playNextChapter = useCallback(() => { |
|
|
|
|
const nextIndex = (activeChapterIndex + 1) % size(chapters) |
|
|
|
|
setPlayerState({ |
|
|
|
|
activeChapterIndex: nextIndex, |
|
|
|
|
loadedProgress: 0, |
|
|
|
|
playedProgress: 0, |
|
|
|
|
playing: nextIndex !== 0, |
|
|
|
|
}) |
|
|
|
|
}, [activeChapterIndex, chapters, setPlayerState]) |
|
|
|
|
|
|
|
|
|
const onPlayerClick = (e: MouseEvent<HTMLDivElement>) => { |
|
|
|
|
if (e.target === videoRef.current) { |
|
|
|
|
togglePlaying() |
|
|
|
|
@ -168,6 +161,8 @@ export const useMultiSourcePlayer = ({ |
|
|
|
|
activeSrc: getActiveChapterUrl(), |
|
|
|
|
chapters, |
|
|
|
|
duration, |
|
|
|
|
isFirstChapterPlaying: activeChapterIndex === 0, |
|
|
|
|
isLastChapterPlaying: activeChapterIndex === numberOfChapters - 1, |
|
|
|
|
loadedProgress, |
|
|
|
|
onError: handleError, |
|
|
|
|
onLoadedProgress, |
|
|
|
|
@ -177,6 +172,7 @@ export const useMultiSourcePlayer = ({ |
|
|
|
|
onQualitySelect, |
|
|
|
|
onReady, |
|
|
|
|
playNextChapter, |
|
|
|
|
playPrevChapter, |
|
|
|
|
playedProgress, |
|
|
|
|
playing, |
|
|
|
|
seek, |
|
|
|
|
|