Revert "Fix HLS jumping to end of timeChunk (#20982)"

This reverts commit 301e0a1a3a.
This commit is contained in:
Nicolas Mowen 2025-11-20 15:17:44 -07:00 committed by GitHub
parent 301e0a1a3a
commit eedf658005
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 17 deletions

View File

@ -135,23 +135,6 @@ export default function HlsVideoPlayer({
if (!useHlsCompat) {
videoRef.current.src = currentSource.playlist;
videoRef.current.load();
// For native HLS, we need to seek after metadata loads since startPosition isn't supported
if (currentSource.startPosition !== undefined) {
videoRef.current.addEventListener(
"loadedmetadata",
() => {
if (videoRef.current && currentSource.startPosition !== undefined) {
// Clamp startPosition to video duration to prevent seeking beyond the end
const clampedPosition = Math.min(
currentSource.startPosition,
videoRef.current.duration || Infinity,
);
videoRef.current.currentTime = clampedPosition;
}
},
{ once: true },
);
}
return;
}

View File

@ -111,6 +111,7 @@ export default function DynamicVideoPlayer({
const [loadingTimeout, setLoadingTimeout] = useState<NodeJS.Timeout>();
const [source, setSource] = useState<HlsSource>({
playlist: `${apiHost}vod/${camera}/start/${timeRange.after}/end/${timeRange.before}/master.m3u8`,
startPosition: startTimestamp ? timeRange.after - startTimestamp : 0,
});
// start at correct time
@ -195,8 +196,26 @@ export default function DynamicVideoPlayer({
playerRef.current.autoplay = !isScrubbing;
}
let startPosition = undefined;
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({
playlist: `${apiHost}vod/${camera}/start/${recordingParams.after}/end/${recordingParams.before}/master.m3u8`,
startPosition,
});
setLoadingTimeout(setTimeout(() => setIsLoading(true), 1000));