-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4914 from voxel51/release/v1.0.1
Release/v1.0.1
- Loading branch information
Showing
38 changed files
with
735 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useTheme } from "@fiftyone/components"; | ||
import type { VideoLooker } from "@fiftyone/looker"; | ||
import { getFrameNumber } from "@fiftyone/looker"; | ||
import { | ||
useCreateTimeline, | ||
useDefaultTimelineNameImperative, | ||
useTimeline, | ||
} from "@fiftyone/playback"; | ||
import * as fos from "@fiftyone/state"; | ||
import React, { useEffect, useMemo, useState } from "react"; | ||
import useLooker from "./use-looker"; | ||
|
||
interface VideoLookerReactProps { | ||
sample: fos.ModalSample; | ||
} | ||
|
||
export const VideoLookerReact = (props: VideoLookerReactProps) => { | ||
const theme = useTheme(); | ||
const { id, looker, sample } = useLooker<VideoLooker>(props); | ||
const [totalFrames, setTotalFrames] = useState<number>(); | ||
const frameRate = useMemo(() => { | ||
return sample.frameRate; | ||
}, [sample]); | ||
|
||
useEffect(() => { | ||
const load = () => { | ||
const duration = looker.getVideo().duration; | ||
setTotalFrames(getFrameNumber(duration, duration, frameRate)); | ||
looker.removeEventListener("load", load); | ||
}; | ||
looker.addEventListener("load", load); | ||
}, [frameRate, looker]); | ||
|
||
return ( | ||
<> | ||
<div | ||
id={id} | ||
data-cy="modal-looker-container" | ||
style={{ | ||
width: "100%", | ||
height: "100%", | ||
background: theme.background.level2, | ||
position: "relative", | ||
}} | ||
/> | ||
{totalFrames !== undefined && ( | ||
<TimelineController looker={looker} totalFrames={totalFrames} /> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
const TimelineController = ({ | ||
looker, | ||
totalFrames, | ||
}: { | ||
looker: VideoLooker; | ||
totalFrames: number; | ||
}) => { | ||
const { getName } = useDefaultTimelineNameImperative(); | ||
const timelineName = React.useMemo(() => getName(), [getName]); | ||
|
||
useCreateTimeline({ | ||
name: timelineName, | ||
config: totalFrames | ||
? { | ||
totalFrames, | ||
loop: true, | ||
} | ||
: undefined, | ||
optOutOfAnimation: true, | ||
}); | ||
|
||
const { pause, play } = useTimeline(timelineName); | ||
|
||
fos.useEventHandler(looker, "pause", pause); | ||
fos.useEventHandler(looker, "play", play); | ||
|
||
return null; | ||
}; |
Oops, something went wrong.