Merge fix-play-behaviour into main
Implements proper play behaviour in track view: - Version switching stops playback and resets UI state - Playback must be started manually after version switch - Added space key shortcut for play/pause toggle - UI elements correctly reflect playback state Fixes playback control issues after version switching Enhances user experience with keyboard shortcuts
This commit is contained in:
@@ -31,6 +31,22 @@ server {
|
|||||||
proxy_send_timeout 300s;
|
proxy_send_timeout 300s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# WebSocket proxy for real-time version room events
|
||||||
|
location /ws/ {
|
||||||
|
proxy_pass http://api:8000;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
|
||||||
|
# WebSocket specific headers
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
|
||||||
|
proxy_read_timeout 60s;
|
||||||
|
proxy_send_timeout 60s;
|
||||||
|
}
|
||||||
|
|
||||||
# SPA routing — all other paths fall back to index.html
|
# SPA routing — all other paths fall back to index.html
|
||||||
location / {
|
location / {
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export function useWaveform(
|
|||||||
const [isPlaying, setIsPlaying] = useState(false);
|
const [isPlaying, setIsPlaying] = useState(false);
|
||||||
const [isReady, setIsReady] = useState(false);
|
const [isReady, setIsReady] = useState(false);
|
||||||
const [currentTime, setCurrentTime] = useState(0);
|
const [currentTime, setCurrentTime] = useState(0);
|
||||||
|
const wasPlayingRef = useRef(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!containerRef.current || !options.url) return;
|
if (!containerRef.current || !options.url) return;
|
||||||
@@ -38,6 +39,9 @@ export function useWaveform(
|
|||||||
ws.on("ready", () => {
|
ws.on("ready", () => {
|
||||||
setIsReady(true);
|
setIsReady(true);
|
||||||
options.onReady?.(ws.getDuration());
|
options.onReady?.(ws.getDuration());
|
||||||
|
// Reset playing state when switching versions
|
||||||
|
setIsPlaying(false);
|
||||||
|
wasPlayingRef.current = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.on("audioprocess", (time) => {
|
ws.on("audioprocess", (time) => {
|
||||||
@@ -45,9 +49,18 @@ export function useWaveform(
|
|||||||
options.onTimeUpdate?.(time);
|
options.onTimeUpdate?.(time);
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.on("play", () => setIsPlaying(true));
|
ws.on("play", () => {
|
||||||
ws.on("pause", () => setIsPlaying(false));
|
setIsPlaying(true);
|
||||||
ws.on("finish", () => setIsPlaying(false));
|
wasPlayingRef.current = true;
|
||||||
|
});
|
||||||
|
ws.on("pause", () => {
|
||||||
|
setIsPlaying(false);
|
||||||
|
wasPlayingRef.current = false;
|
||||||
|
});
|
||||||
|
ws.on("finish", () => {
|
||||||
|
setIsPlaying(false);
|
||||||
|
wasPlayingRef.current = false;
|
||||||
|
});
|
||||||
|
|
||||||
wsRef.current = ws;
|
wsRef.current = ws;
|
||||||
return () => {
|
return () => {
|
||||||
@@ -57,8 +70,14 @@ export function useWaveform(
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [options.url]);
|
}, [options.url]);
|
||||||
|
|
||||||
const play = () => wsRef.current?.play();
|
const play = () => {
|
||||||
const pause = () => wsRef.current?.pause();
|
wsRef.current?.play();
|
||||||
|
wasPlayingRef.current = true;
|
||||||
|
};
|
||||||
|
const pause = () => {
|
||||||
|
wsRef.current?.pause();
|
||||||
|
wasPlayingRef.current = false;
|
||||||
|
};
|
||||||
const seekTo = (time: number) => {
|
const seekTo = (time: number) => {
|
||||||
if (wsRef.current && isReady) {
|
if (wsRef.current && isReady) {
|
||||||
wsRef.current.setTime(time);
|
wsRef.current.setTime(time);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useRef, useState, useCallback } from "react";
|
import { useRef, useState, useCallback, useEffect } from "react";
|
||||||
import { useParams, Link } from "react-router-dom";
|
import { useParams, Link } from "react-router-dom";
|
||||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { api } from "../api/client";
|
import { api } from "../api/client";
|
||||||
@@ -42,6 +42,23 @@ export function SongPage() {
|
|||||||
peaksUrl: activeVersion ? `/api/v1/versions/${activeVersion}/waveform` : null,
|
peaksUrl: activeVersion ? `/api/v1/versions/${activeVersion}/waveform` : null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add space key shortcut for play/pause
|
||||||
|
useEffect(() => {
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.code === "Space") {
|
||||||
|
e.preventDefault();
|
||||||
|
if (isPlaying) {
|
||||||
|
pause();
|
||||||
|
} else {
|
||||||
|
play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
||||||
|
}, [isPlaying, play, pause]);
|
||||||
|
|
||||||
const { data: comments } = useQuery({
|
const { data: comments } = useQuery({
|
||||||
queryKey: ["comments", songId],
|
queryKey: ["comments", songId],
|
||||||
queryFn: () => api.get<SongComment[]>(`/songs/${songId}/comments`),
|
queryFn: () => api.get<SongComment[]>(`/songs/${songId}/comments`),
|
||||||
|
|||||||
Reference in New Issue
Block a user