Skip to content

Commit

Permalink
play/pause on space
Browse files Browse the repository at this point in the history
  • Loading branch information
sashankaryal committed Sep 19, 2024
1 parent c2d41ec commit 75bafa6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
15 changes: 2 additions & 13 deletions app/packages/looker/src/elements/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright 2017-2024, Voxel51, Inc.
*/

import { is } from "immutable";
import { SCALE_FACTOR } from "../../constants";
import { ImaVidFramesController } from "../../lookers/imavid/controller";
import {
Expand Down Expand Up @@ -477,18 +476,8 @@ export const playPause: Control<VideoState | ImaVidState> = {
const isImaVid = (state.config as ImaVidConfig)
.frameStoreController as ImaVidFramesController;
if (isImaVid) {
const {
currentFrameNumber,
playing,
config: { frameStoreController },
} = state as ImaVidState;
const reachedEnd =
currentFrameNumber >= frameStoreController.totalFrameCount;
return {
currentFrameNumber: reachedEnd ? 1 : currentFrameNumber,
options: { showJSON: false },
playing: !playing || reachedEnd,
};
// do nothing, is handled in React component
return {};
}

const {
Expand Down
21 changes: 20 additions & 1 deletion app/packages/playback/src/lib/use-create-timeline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Optional, useEventHandler } from "@fiftyone/state";
import { Optional, useEventHandler, useKeyDown } from "@fiftyone/state";
import { useAtomValue, useSetAtom } from "jotai";
import { useAtomCallback } from "jotai/utils";
import { useCallback, useEffect, useMemo, useRef } from "react";
Expand Down Expand Up @@ -282,6 +282,10 @@ export const useCreateTimeline = (
)
);

/**
* This effect synchronizes all timelines with the frame number
* on load.
*/
useEffect(() => {
if (!isTimelineInitialized) {
return;
Expand All @@ -292,5 +296,20 @@ export const useCreateTimeline = (
});
}, [isTimelineInitialized, refresh]);

const spaceKeyDownHandler = useCallback(
(_, e: KeyboardEvent) => {
if (playHeadState === "paused") {
play();
} else {
pause();
}
e.stopPropagation();
e.preventDefault();
},
[play, pause, playHeadState]
);

useKeyDown(" ", spaceKeyDownHandler, [spaceKeyDownHandler]);

return { isTimelineInitialized, refresh, subscribe };
};

0 comments on commit 75bafa6

Please sign in to comment.