diff --git a/lib/playback/index.ts b/lib/playback/index.ts index 5f770ce..79c98d3 100644 --- a/lib/playback/index.ts +++ b/lib/playback/index.ts @@ -210,6 +210,10 @@ export class Player { return this.#catalog.tracks.filter(Catalog.isAudioTrack).map((track) => track.name) } + isPaused() { + return this.#paused + } + async switchTrack(trackname: string) { const currentTrack = this.getCurrentTrack() if (this.#paused) { diff --git a/web/src/components/play-button.tsx b/web/src/components/play-button.tsx index 1af96c1..9d9acd9 100644 --- a/web/src/components/play-button.tsx +++ b/web/src/components/play-button.tsx @@ -1,19 +1,28 @@ type PlayButtonProps = { - play: () => void + onClick: () => Promise + isPlaying: boolean } export const PlayButton = (props: PlayButtonProps) => { return ( ) } diff --git a/web/src/components/watch.tsx b/web/src/components/watch.tsx index 034e930..cc78ce2 100644 --- a/web/src/components/watch.tsx +++ b/web/src/components/watch.tsx @@ -16,6 +16,7 @@ export default function Watch(props: { name: string }) { const [error, setError] = createSignal() const [player, setPlayer] = createSignal() + const [isPlaying, setIsPlaying] = createSignal(!player()?.isPaused()) const [showCatalog, setShowCatalog] = createSignal(false) const [hovered, setHovered] = createSignal(false) const [showControls, setShowControls] = createSignal(true) @@ -43,11 +44,17 @@ export default function Watch(props: { name: string }) { return player()?.getVideoTracks() } - const handlePlayPause = () => { - const playerInstance = player() - if (!playerInstance) return + const handlePlayPause = async () => { + const instance = player() + if (!instance) return - player()?.play().catch(setError) + if (instance.isPaused()) { + await instance.play() + setIsPlaying(true) + } else { + await instance.play() // Assuming the same method toggles play/pause + setIsPlaying(false) + } } // The JSON catalog for debugging. @@ -85,7 +92,7 @@ export default function Watch(props: { name: string }) {
void handlePlayPause()} class="h-full w-full rounded-lg" onMouseEnter={() => setHovered(true)} onMouseLeave={() => setHovered(false)} @@ -95,7 +102,7 @@ export default function Watch(props: { name: string }) { showControls() ? "opacity-100" : "opacity-0" } absolute bottom-4 flex h-[40px] w-[100%] items-center gap-[4px] rounded transition-opacity duration-200 `} > - +