Download code/frontend/apps/web/src/lib/use-timeline-player.ts from Jiali9/Affect-Atlas: direct link, hf CLI and curl.
- Browser
- Download file 982 Bytes
-
https://huggingface.co/Jiali9/Affect-Atlas/resolve/main/code/frontend/apps/web/src/lib/use-timeline-player.ts
- Command line
-
hf download hf://Jiali9/Affect-Atlas/code/frontend/apps/web/src/lib/use-timeline-player.ts
-
curl -L -o use-timeline-player.ts https://huggingface.co/Jiali9/Affect-Atlas/resolve/main/code/frontend/apps/web/src/lib/use-timeline-player.ts
982 Bytes
| import { useRef, useState } from 'react' | |
| import type { TimelinePoint } from './api' | |
| export function useTimelinePlayer() { | |
| const audioRef = useRef<HTMLAudioElement | null>(null) | |
| const [currentTime, setCurrentTime] = useState(0) | |
| const [selectedIndex, setSelectedIndex] = useState<number | null>(null) | |
| const selectWindow = (point: TimelinePoint) => { | |
| setSelectedIndex(point.index) | |
| if (audioRef.current) audioRef.current.currentTime = point.start_seconds | |
| setCurrentTime(point.start_seconds) | |
| } | |
| const seek = (time: number) => { | |
| if (audioRef.current) audioRef.current.currentTime = time | |
| setCurrentTime(time) | |
| setSelectedIndex(null) | |
| } | |
| const reset = () => { | |
| audioRef.current?.pause() | |
| if (audioRef.current) audioRef.current.currentTime = 0 | |
| setCurrentTime(0) | |
| setSelectedIndex(null) | |
| } | |
| return { audioRef, currentTime, selectedIndex, selectWindow, seek, reset, onTimeUpdate: () => setCurrentTime(audioRef.current?.currentTime ?? 0) } | |
| } | |