From b04ecbe54d2cb0581b8b33a46dc07d5d5e978c13 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Wed, 11 Sep 2024 16:20:20 +0100 Subject: [PATCH] hls buffering tweaks (#5266) --- .../post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx | 8 +++++++- .../util/post-embeds/VideoEmbedInner/VideoWebControls.tsx | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx b/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx index a30c0e1e..441be757 100644 --- a/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx +++ b/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb.tsx @@ -35,7 +35,13 @@ export function VideoEmbedInnerWeb({ if (!ref.current) return if (!Hls.isSupported()) throw new HLSUnsupportedError() - const hls = new Hls({capLevelToPlayerSize: true}) + const hls = new Hls({ + capLevelToPlayerSize: true, + maxMaxBufferLength: 10, // only load 10s ahead + // note: the amount buffered is affected by both maxBufferLength and maxBufferSize + // it will buffer until it it's greater than *both* of those values + // so we use maxMaxBufferLength to set the actual maximum amount of buffering instead + }) hlsRef.current = hls hls.attachMedia(ref.current) diff --git a/src/view/com/util/post-embeds/VideoEmbedInner/VideoWebControls.tsx b/src/view/com/util/post-embeds/VideoEmbedInner/VideoWebControls.tsx index 3fd32269..138791e4 100644 --- a/src/view/com/util/post-embeds/VideoEmbedInner/VideoWebControls.tsx +++ b/src/view/com/util/post-embeds/VideoEmbedInner/VideoWebControls.tsx @@ -130,8 +130,12 @@ export function Controls({ if (focused) { // auto decide quality based on network conditions hlsRef.current.autoLevelCapping = -1 + // allow 30s of buffering + hlsRef.current.config.maxMaxBufferLength = 30 } else { + // back to what we initially set hlsRef.current.autoLevelCapping = 0 + hlsRef.current.config.maxMaxBufferLength = 10 } }, [hlsRef, focused])