mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-16 02:44:51 +00:00
fix(startTime): fix start time on web
This commit is contained in:
+2
-14
@@ -1,13 +1,7 @@
|
||||
import { createPlayer } from "@videojs/react";
|
||||
import { GoogleCast } from "@videojs/react/media/google-cast";
|
||||
import { videoFeatures } from "@videojs/react/video";
|
||||
import {
|
||||
createContext,
|
||||
type ReactNode,
|
||||
useContext,
|
||||
useEffect,
|
||||
useRef,
|
||||
} from "react";
|
||||
import { createContext, type ReactNode, useContext, useEffect } from "react";
|
||||
import { usePlayerState } from "./events";
|
||||
import { WebOmniPlayer } from "./player.web";
|
||||
import type { OmniPlayer, PlayerBackend } from "./types/player";
|
||||
@@ -58,16 +52,10 @@ const PlayerInitializer = ({
|
||||
}) => {
|
||||
const store = VideoPlayer.usePlayer();
|
||||
const player = useLazyRef(() => new WebOmniPlayer(store));
|
||||
const seekedForSrc = useRef<string | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
player.source = source;
|
||||
const uri = source?.src?.uri;
|
||||
if (uri !== seekedForSrc.current) {
|
||||
seekedForSrc.current = uri;
|
||||
if (source?.startTime) store.seek(source.startTime);
|
||||
}
|
||||
}, [source, store]);
|
||||
}, [source]);
|
||||
|
||||
useEffect(() => {
|
||||
player.showNotification = showNotification;
|
||||
|
||||
@@ -134,6 +134,17 @@ export const OmniView = ({
|
||||
[],
|
||||
);
|
||||
|
||||
const player = usePlayer();
|
||||
const uri = source?.src.uri;
|
||||
const startTime = source?.startTime;
|
||||
const prevUri = useRef<string | undefined>(undefined);
|
||||
useEffect(() => {
|
||||
if (!uri) return;
|
||||
if (startTime) player.currentTime = startTime;
|
||||
if (autoplay && prevUri.current && prevUri.current !== uri) player.play();
|
||||
prevUri.current = uri;
|
||||
}, [player, uri, startTime, autoplay]);
|
||||
|
||||
// While casting, the receiver renders subtitles (the player forwards the
|
||||
// selection); skip rendering them locally on the idle <video>.
|
||||
const castStatus = usePlayerState("castStatus");
|
||||
|
||||
Reference in New Issue
Block a user