Cleanup scrubbing logic

This commit is contained in:
Nicolas Mowen 2024-03-14 08:12:43 -06:00
parent 7957315e3f
commit cab4336b7f
3 changed files with 16 additions and 27 deletions

View File

@ -47,10 +47,6 @@ export class DynamicVideoController {
}
seekToTimestamp(time: number, play: boolean = false) {
if (this.playerMode != "playback") {
this.playerMode = "playback";
}
if (
this.recordings.length == 0 ||
time < this.recordings[0].start_time ||
@ -60,6 +56,10 @@ export class DynamicVideoController {
return;
}
if (this.playerMode != "playback") {
this.playerMode = "playback";
}
let seekSeconds = 0;
(this.recordings || []).every((segment) => {
// if the next segment is past the desired time, stop calculating

View File

@ -133,6 +133,10 @@ export default function DynamicVideoPlayer({
return;
}
if (playerRef.current) {
playerRef.current.autoplay = !isScrubbing;
}
setSource(
`${apiHost}vod/${camera}/start/${timeRange.start}/end/${timeRange.end}/master.m3u8`,
);

View File

@ -89,13 +89,16 @@ export function DesktopRecordingView({
const [playerTime, setPlayerTime] = useState(startTime);
const updateSelectedSegment = useCallback(
(currentTime: number) => {
(currentTime: number, updateStartTime: boolean) => {
const index = timeRange.ranges.findIndex(
(seg) => seg.start <= currentTime && seg.end >= currentTime,
);
if (index != -1) {
setPlaybackStart(currentTime);
if (updateStartTime) {
setPlaybackStart(currentTime);
}
setSelectedRangeIdx(index);
}
},
@ -108,7 +111,7 @@ export function DesktopRecordingView({
currentTime > currentTimeRange.end + 60 ||
currentTime < currentTimeRange.start - 60
) {
updateSelectedSegment(currentTime);
updateSelectedSegment(currentTime, false);
return;
}
@ -126,40 +129,22 @@ export function DesktopRecordingView({
updateSelectedSegment,
]);
useEffect(() => {
if (!scrubbing) {
if (
currentTimeRange.start <= currentTime &&
currentTimeRange.end >= currentTime
) {
mainControllerRef.current?.seekToTimestamp(currentTime, true);
} else {
updateSelectedSegment(currentTime);
}
}
// we only want to seek when user stops scrubbing
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [scrubbing]);
useEffect(() => {
if (!scrubbing) {
if (Math.abs(currentTime - playerTime) > 10) {
mainControllerRef.current?.pause();
if (
currentTimeRange.start <= currentTime &&
currentTimeRange.end >= currentTime
) {
mainControllerRef.current?.seekToTimestamp(currentTime, true);
} else {
updateSelectedSegment(currentTime);
updateSelectedSegment(currentTime, true);
}
}
}
// we only want to seek when current time doesn't match the player update time
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentTime]);
}, [currentTime, scrubbing]);
const onSelectCamera = useCallback(
(newCam: string) => {