Fix HLS jumping to end of timeChunk (#20982)

* Fix HLS jumping to end

* Undo
This commit is contained in:
Nicolas Mowen
2025-11-20 15:50:00 -06:00
committed by GitHub
parent 213a1fbd00
commit 301e0a1a3a
2 changed files with 17 additions and 19 deletions
@@ -135,6 +135,23 @@ 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;
}