Don't set start position if it is not valid

This commit is contained in:
Nicolas Mowen 2025-08-14 10:04:37 -06:00
parent ea9e98ab78
commit e58c02aa0e
3 changed files with 18 additions and 9 deletions

View File

@ -109,7 +109,6 @@ export function GenericVideoPlayer({
videoRef={videoRef} videoRef={videoRef}
currentSource={{ currentSource={{
playlist: source, playlist: source,
startPosition: 0,
}} }}
hotKeys hotKeys
visible visible

View File

@ -30,7 +30,7 @@ const unsupportedErrorCodes = [
export interface HlsSource { export interface HlsSource {
playlist: string; playlist: string;
startPosition: number; startPosition?: number;
} }
type HlsVideoPlayerProps = { type HlsVideoPlayerProps = {

View File

@ -185,16 +185,26 @@ export default function DynamicVideoPlayer({
playerRef.current.autoplay = !isScrubbing; playerRef.current.autoplay = !isScrubbing;
} }
const inpointOffset = calculateInpointOffset( let startPosition = undefined;
recordingParams.after,
(recordings || [])[0], if (startTimestamp) {
); const inpointOffset = calculateInpointOffset(
recordingParams.after,
(recordings || [])[0],
);
const idealStartPosition = Math.max(
0,
startTimestamp - timeRange.after - inpointOffset,
);
if (idealStartPosition >= recordings[0].start_time - timeRange.after) {
startPosition = idealStartPosition;
}
}
setSource({ setSource({
playlist: `${apiHost}vod/${camera}/start/${recordingParams.after}/end/${recordingParams.before}/master.m3u8`, playlist: `${apiHost}vod/${camera}/start/${recordingParams.after}/end/${recordingParams.before}/master.m3u8`,
startPosition: startTimestamp startPosition,
? Math.max(0, startTimestamp - timeRange.after - inpointOffset)
: 0,
}); });
setLoadingTimeout(setTimeout(() => setIsLoading(true), 1000)); setLoadingTimeout(setTimeout(() => setIsLoading(true), 1000));