feat: add preservePosition option to loadVideoSource

This commit is contained in:
2026-07-04 05:02:19 +02:00
parent 660ae022ea
commit 3ed092c5c5

View File

@@ -43,14 +43,19 @@ const shouldUseHLS = (type: string | undefined, url: string): boolean => {
* Some browsers can be flaky when switching between HLS URLs while playing. Clearing `src` first
* ensures the media element fully resets before the new URL is set.
*/
export const loadVideoSource = (url: string, type?: string, startTimeSeconds?: number): void => {
export const loadVideoSource = (
url: string,
type?: string,
startTimeSeconds?: number,
preservePosition: boolean = true,
): void => {
if (!url) {
return;
}
const wasPlaying = !state.elements.video.paused;
const prevDisplayTime = displayTimeFromAbsolute(state.elements.video.currentTime);
const shouldPreservePosition = prevDisplayTime > 0;
const shouldPreservePosition = preservePosition && prevDisplayTime > 0;
// Fully reset the element before setting a new source.
destroyVideoSource();