Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playback rate #34

Merged
merged 3 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"license": "MIT",
"devDependencies": {
"@tauri-apps/cli": "^1.5.6",
"@tauri-apps/cli": "^1.5.8",
"@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.5",
"autoprefixer": "^10.4.16",
Expand Down
16 changes: 16 additions & 0 deletions src/components/main-view/Camera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
endVideoEvent,
isPlaying,
ontimeupdateEvent,
playbackRate,
setIsPlaying,
startAt,
} from "../../stores";
Expand Down Expand Up @@ -55,6 +56,21 @@ export function Camera(props: CameraProps) {
}
});

createEffect(() => {
const _playbackRate = playbackRate();

const videoElement = document.getElementById(
props.id
) as HTMLVideoElement;

if (!videoElement) {
return;
}

videoElement.defaultPlaybackRate = _playbackRate;
videoElement.playbackRate = _playbackRate;
});

// const handlePause = () => {
// console.log("pause");
// if (isPlaying()) {
Expand Down
27 changes: 25 additions & 2 deletions src/components/main-view/Timelime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import {
selectedOccurrence,
selectedOccurrenceFiles,
setChangeCurrentTime,
setPlaybackRate,
setFilesByOccurrences,
setIsPlaying,
setSelectedOccurrence,
playbackRate,
} from "../../stores";
import { Button } from "../../ui";
import { Button, Dropdown } from "../../ui";
import timelineStyles from "./Timelime.module.css";
import { tauri } from "../../utils";

Expand Down Expand Up @@ -188,7 +190,10 @@ export function Timeline() {
return (
<div class="h-16 p-2 flex w-full gap-2">
<div class="flex">
<Button onClick={() => setIsPlaying((playing) => !playing)}>
<Button
onClick={() => setIsPlaying((playing) => !playing)}
class="bg-transparent dark:bg-transparent"
>
<i
class={
"mx-2 fa-solid fa-fw " +
Expand All @@ -197,6 +202,24 @@ export function Timeline() {
/>
</Button>
</div>
<div class="flex">
<Dropdown
class="bg-transparent dark:bg-transparent"
options={[
{ label: "x0.5", value: "0.5" },
{ label: "x0.75", value: "0.75" },
{ label: "x1", value: "1" },
{ label: "x1.25", value: "1.25" },
{ label: "x1.5", value: "1.5" },
{ label: "x2", value: "2" },
{ label: "x4", value: "4" },
]}
value={String(playbackRate())}
onSelect={(value) =>
setPlaybackRate(parseFloat(value.value))
}
/>
</div>
<div
class="flex-grow overflow-hidden relative"
onMouseDown={onMouseDown}
Expand Down
2 changes: 1 addition & 1 deletion src/components/navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function Navbar() {

return (
<div class="h-16 p-2 flex w-full items-center gap-2">
<Button onClick={toggleSidebar}>
<Button onClick={toggleSidebar} class="bg-transparent dark:bg-transparent">
<i class="mx-2 fa-solid fa-fw fa-bars" />
</Button>
<div class="flex">
Expand Down
2 changes: 1 addition & 1 deletion src/components/sidebar/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function SidebarHeader() {
return (
<div class="flex w-full truncate">
<div class="flex grow items-center">
<Button onClick={toggleSidebar} class="dark:bg-white">
<Button onClick={toggleSidebar} class="bg-transparent dark:bg-transparent">
<i class="mx-2 fa-solid fa-fw fa-bars" />
</Button>
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/stores/occurrences.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export const [selectedOccurrence, setSelectedOccurrence] =

export const [currentTime, setCurrentTime] = createSignal<number>(0);
export const [isPlaying, setIsPlaying] = createSignal<boolean>(false);
export const [playbackRate, setPlaybackRate] =
createSignal<number>(1);

createEffect(() => {
// on select occurence auto play the video
Expand Down
3 changes: 2 additions & 1 deletion src/ui/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export function Button(props: ButtonProps) {
"hover:bg-slate-300 " +
"dark:hover:bg-slate-600 " +
"focus:outline-none focus:bg-slate-400 active:bg-slate-400 " +
"dark:focus:bg-slate-500 dark:active:bg-slate-500 "
"dark:focus:bg-slate-500 dark:active:bg-slate-500 " +
props.class || ""
}
onClick={onClick}
>
Expand Down
61 changes: 61 additions & 0 deletions src/ui/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { For, createSignal } from "solid-js";
import { uuidv4 } from "../utils";
import Button from "./Button";

interface Option {
label: string;
value: string;
}

interface DropdownProps {
value: string;
placeholder?: string;
options: Option[];
class?: string;
onSelect?: (value: Option) => void;
}

export function Dropdown(props: DropdownProps) {
const uuid = uuidv4();

const [selected, setSelected] = createSignal<Option | undefined>(undefined);

const onSelect = (e: Event) => {
const target = e.target as HTMLSelectElement;
const selectedOption = props.options.find(
(option) => option.value === target.value
);

if (!selectedOption) {
return;
}

setSelected(selectedOption);
props.onSelect && props.onSelect(selectedOption);
};

return (
<>
<Button class={"relative w-14 " + props.class || ""}>
{selected()?.label ||
props.value ||
props.placeholder ||
"Select"}
<select
id={uuid}
class="opacity-0 absolute top-0 left-0 w-full h-full cursor-pointer"
onChange={(e) => onSelect(e)}
value={props.value}
>
<For each={props.options}>
{(option) => (
<option value={option.value}>{option.label}</option>
)}
</For>
</select>
</Button>
</>
);
}

export default Dropdown;
4 changes: 2 additions & 2 deletions src/ui/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

export * from './Button';
export * from "./Button";
export * from "./Dropdown";