Unload HLS on unmount (#19747)

* Unload HLS player on unmount so segments don't continue to load

* Add query arg for event padding
This commit is contained in:
Nicolas Mowen
2025-08-25 13:33:17 -05:00
committed by GitHub
parent 4347402fcc
commit 4fcb1ea7ac
2 changed files with 20 additions and 10 deletions
+9 -7
View File
@@ -123,13 +123,6 @@ export default function HlsVideoPlayer({
return;
}
// we must destroy the hlsRef every time the source changes
// so that we can create a new HLS instance with startPosition
// set at the optimal point in time
if (hlsRef.current) {
hlsRef.current.destroy();
}
hlsRef.current = new Hls({
maxBufferLength: 10,
maxBufferSize: 20 * 1000 * 1000,
@@ -138,6 +131,15 @@ export default function HlsVideoPlayer({
hlsRef.current.attachMedia(videoRef.current);
hlsRef.current.loadSource(currentSource.playlist);
videoRef.current.playbackRate = currentPlaybackRate;
return () => {
// we must destroy the hlsRef every time the source changes
// so that we can create a new HLS instance with startPosition
// set at the optimal point in time
if (hlsRef.current) {
hlsRef.current.destroy();
}
}
}, [videoRef, hlsRef, useHlsCompat, currentSource]);
// state handling