Skip to content

Commit

Permalink
Improve sceneplayer end time handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dogwithakeyboard committed Feb 8, 2025
1 parent b4fb500 commit 5ea1d2f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
24 changes: 15 additions & 9 deletions ui/v2.5/src/components/ScenePlayer/ScenePlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ interface IScenePlayerProps {
autoplay?: boolean;
permitLoop?: boolean;
initialTimestamp: number;
initialEndstamp: number;
endTime: number | null;
sendSetTimestamp: (setTimestamp: (value: number) => void) => void;
onComplete: () => void;
onNext: () => void;
Expand All @@ -216,7 +216,7 @@ export const ScenePlayer: React.FC<IScenePlayerProps> = ({
autoplay,
permitLoop = true,
initialTimestamp: _initialTimestamp,
initialEndstamp,
endTime: endTime,
sendSetTimestamp,
onComplete,
onNext,
Expand Down Expand Up @@ -692,6 +692,7 @@ export const ScenePlayer: React.FC<IScenePlayerProps> = ({
uiConfig?.alwaysStartFromBeginning,
uiConfig?.disableMobileMediaAutoRotateEnabled,
_initialTimestamp,
endTime,
]);

useEffect(() => {
Expand Down Expand Up @@ -795,17 +796,22 @@ export const ScenePlayer: React.FC<IScenePlayerProps> = ({
// Try to detect that the player has passed the end point of a Marker
useEffect(() => {
const player = getPlayer();
if (!player || !initialEndstamp) return;
player.on("timeupdate", function () {
if (!player || !endTime) return;
function markerComplete(this: VideoJsPlayer) {
if (
player.currentTime() >= initialEndstamp &&
player.currentTime() <= initialEndstamp + 0.5
!this.paused() &&
endTime &&
this.currentTime() >= endTime &&
this.currentTime() <= endTime + 1
) {
player.pause();
onComplete();
}
});
}, [getPlayer, initialEndstamp, onComplete]);
}
player.on("timeupdate", markerComplete);
return () => {
player.off("timeupdate", markerComplete);
};
}, [getPlayer, onComplete, endTime]);

function onScrubberScroll() {
if (started.current) {
Expand Down
14 changes: 13 additions & 1 deletion ui/v2.5/src/components/Scenes/SceneDetails/Scene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const VideoFrameRateResolution: React.FC<{
interface IProps {
scene: GQL.SceneDataFragment;
setTimestamp: (num: number) => void;
setEndstamp: (num: number) => void;
queueScenes: QueuedItem[];
onQueueNext: () => void;
onQueuePrevious: () => void;
Expand Down Expand Up @@ -710,6 +711,7 @@ const SceneLoader: React.FC<RouteComponentProps<ISceneParams>> = ({
);

const _setTimestamp = useRef<(value: number) => void>();
const _setEndstamp = useRef<(value: number | null) => void>();
const initialTimestamp = useMemo(() => {
return Number.parseInt(queryParams.get("t")?.split(",")[0] ?? "0", 10);
}, [queryParams]);
Expand Down Expand Up @@ -749,6 +751,12 @@ const SceneLoader: React.FC<RouteComponentProps<ISceneParams>> = ({
}
}

function setEndstamp(value: number | null) {
if (_setEndstamp.current) {
_setEndstamp.current(value);
}
}

// set up hotkeys
useEffect(() => {
Mousetrap.bind(".", () => setHideScrubber((value) => !value));
Expand Down Expand Up @@ -887,6 +895,9 @@ const SceneLoader: React.FC<RouteComponentProps<ISceneParams>> = ({
// Scene page does not reload if the sceneid is the same so move timeline to marker.
if (queuedScene.scene.id == id) {
setTimestamp(queuedScene.seconds);
// Set new marker endtime.
const end_seconds = queuedScene.end_seconds ?? null;
setEndstamp(end_seconds);
}
} else if (queuedScene.__typename == "Scene") {
loadScene(
Expand Down Expand Up @@ -1041,6 +1052,7 @@ const SceneLoader: React.FC<RouteComponentProps<ISceneParams>> = ({
<ScenePage
scene={scene}
setTimestamp={setTimestamp}
setEndstamp={setEndstamp}
queueScenes={queueScenes}
queueStart={queueStart}
onDelete={onDelete}
Expand All @@ -1065,7 +1077,7 @@ const SceneLoader: React.FC<RouteComponentProps<ISceneParams>> = ({
autoplay={autoplay}
permitLoop={!continuePlaylist}
initialTimestamp={initialTimestamp}
initialEndstamp={initialEndstamp}
endTime={initialEndstamp}
sendSetTimestamp={getSetTimestamp}
onComplete={onComplete}
onNext={() => queueNext(true)}
Expand Down

0 comments on commit 5ea1d2f

Please sign in to comment.