diff options
| author | Hyteq <DerpsDer.es@gmail.com> | 2025-06-23 09:18:15 +0300 |
|---|---|---|
| committer | Hyteq <DerpsDer.es@gmail.com> | 2025-06-23 09:18:15 +0300 |
| commit | ed6ab6cd5b6fec5f8e7d7cbcaa5224393729164e (patch) | |
| tree | c9df67eeec551f40737b1b26ab7e992c8b55c3e2 /apps/web/src/stores | |
| parent | 589f4a20a170c221203f7515622c38900e2efde4 (diff) | |
| download | opencut-ed6ab6cd5b6fec5f8e7d7cbcaa5224393729164e.tar.gz | |
feat: cleaned up video player, added functionality, zooming in/out, timeline position viewer, keyboard controls
Diffstat (limited to 'apps/web/src/stores')
| -rw-r--r-- | apps/web/src/stores/playback-store.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/apps/web/src/stores/playback-store.ts b/apps/web/src/stores/playback-store.ts new file mode 100644 index 00000000..7db1fb93 --- /dev/null +++ b/apps/web/src/stores/playback-store.ts @@ -0,0 +1,30 @@ +import { create } from "zustand"; +import type { PlaybackState, PlaybackControls } from "@/types/playback"; + +interface PlaybackStore extends PlaybackState, PlaybackControls { + setDuration: (duration: number) => void; + setCurrentTime: (time: number) => void; +} + +export const usePlaybackStore = create<PlaybackStore>((set, get) => ({ + isPlaying: false, + currentTime: 0, + duration: 0, + volume: 1, + + play: () => set({ isPlaying: true }), + pause: () => set({ isPlaying: false }), + toggle: () => set((state) => ({ isPlaying: !state.isPlaying })), + seek: (time: number) => { + const { duration } = get(); + const clampedTime = Math.max(0, Math.min(duration, time)); + set({ currentTime: clampedTime }); + + // Notify video element to seek + const event = new CustomEvent('playback-seek', { detail: { time: clampedTime } }); + window.dispatchEvent(event); + }, + setVolume: (volume: number) => set({ volume: Math.max(0, Math.min(1, volume)) }), + setDuration: (duration: number) => set({ duration }), + setCurrentTime: (time: number) => set({ currentTime: time }), +}));
\ No newline at end of file |
