|
|
|
|
@ -20,6 +20,7 @@ import { useVideoQuality } from './useVideoQuality' |
|
|
|
|
import { useDuration } from './useDuration' |
|
|
|
|
import type { Chapters } from '../types' |
|
|
|
|
import { Players } from '../types' |
|
|
|
|
import { getNextPlayer } from '../helpers' |
|
|
|
|
|
|
|
|
|
export type PlayerState = { |
|
|
|
|
activeChapterIndex: number, |
|
|
|
|
@ -64,7 +65,7 @@ export const useMultiSourcePlayer = ({ |
|
|
|
|
const numberOfChapters = size(chapters) |
|
|
|
|
const [ |
|
|
|
|
{ |
|
|
|
|
activeChapterIndex, |
|
|
|
|
activeChapterIndex: chapterIndex, |
|
|
|
|
activePlayer, |
|
|
|
|
loadedProgress, |
|
|
|
|
playedProgress, |
|
|
|
|
@ -77,6 +78,7 @@ export const useMultiSourcePlayer = ({ |
|
|
|
|
] = useObjectState({ ...initialState, activeChapterIndex: resumeFrom.half }) |
|
|
|
|
const video1Ref = useRef<HTMLVideoElement>(null) |
|
|
|
|
const video2Ref = useRef<HTMLVideoElement>(null) |
|
|
|
|
const activeChapterIndex = numberOfChapters >= chapterIndex ? chapterIndex : 0 |
|
|
|
|
const { |
|
|
|
|
onReady, |
|
|
|
|
playNextChapter, |
|
|
|
|
@ -145,6 +147,15 @@ export const useMultiSourcePlayer = ({ |
|
|
|
|
onPlayingChange(playing) |
|
|
|
|
}, [playing, onPlayingChange]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
setPlayerState((state) => ({ |
|
|
|
|
...initialState, |
|
|
|
|
activePlayer: getNextPlayer(state.activePlayer), |
|
|
|
|
playing: state.playing, |
|
|
|
|
ready: state.ready, |
|
|
|
|
})) |
|
|
|
|
}, [chapters, setPlayerState]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
const progressSeconds = playedProgress / 1000 |
|
|
|
|
const { period } = chapters[activeChapterIndex] |
|
|
|
|
|