fix(source): ensure object update doesn't reset player

This commit is contained in:
2026-07-16 12:27:50 +02:00
parent 61ee6238d5
commit 645b226359
3 changed files with 27 additions and 12 deletions
+13 -2
View File
@@ -1,6 +1,12 @@
import { createPlayer } from "@videojs/react";
import { videoFeatures } from "@videojs/react/video";
import { createContext, type ReactNode, useContext, useEffect } from "react";
import {
createContext,
type ReactNode,
useContext,
useEffect,
useRef,
} from "react";
import { WebOmniPlayer } from "./player.web";
import type { OmniPlayer } from "./types/player";
import type { Source } from "./types/source";
@@ -39,10 +45,15 @@ const PlayerInitializer = ({
}) => {
const store = VideoPlayer.usePlayer();
const player = useLazyRef(() => new WebOmniPlayer(store));
const seekedForSrc = useRef<string | undefined>(undefined);
useEffect(() => {
player.source = source;
if (source.startTime) store.seek(source.startTime).catch(() => {});
const uri = source.src[0]?.uri;
if (uri !== seekedForSrc.current) {
seekedForSrc.current = uri;
if (source.startTime) store.seek(source.startTime)
}
}, [source, store]);
useEffect(() => {