Fix pause/resume desync by stopping and restarting stream at offset instead of SIGSTOP/SIGCONT

This commit is contained in:
MiTHRAL 2026-05-26 18:26:58 -04:00
parent 0edacd59da
commit fcb03ad8c2

View file

@ -563,22 +563,22 @@ const server = http.createServer(async (request, response) => {
const action = String(body.action || "").trim(); const action = String(body.action || "").trim();
if (action === "pause") { if (action === "pause") {
if (!canPauseCommand(session.ffmpegCommand)) { if (session.playbackState !== "playing") {
throw new Error("Pause is not available because FFmpeg is not active"); throw new Error("Pause is not available because session is not playing");
} }
session.positionSeconds = sessionPlaybackPosition(session); const pausedPos = sessionPlaybackPosition(session);
session.startedAtSeconds = 0; await stopSessionPlayback(session, false);
session.ffmpegCommand.ffmpegProc.kill("SIGSTOP"); session.positionSeconds = pausedPos;
session.playbackState = "paused"; session.playbackState = "paused";
session.workerStatus = "connected"; session.workerStatus = "connected";
} else if (action === "resume") { } else if (action === "resume") {
if (!canPauseCommand(session.ffmpegCommand)) { if (session.playbackState !== "paused") {
throw new Error("Resume is not available because FFmpeg is not active"); throw new Error("Resume is not available because session is not paused");
} }
session.startedAtSeconds = nowSeconds(); if (!session.playback) {
session.ffmpegCommand.ffmpegProc.kill("SIGCONT"); throw new Error("Cannot resume because no playback metadata exists");
session.playbackState = "playing"; }
session.workerStatus = "streaming"; await startPlayback(session, session.playback, session.positionSeconds);
} else if (action === "stop" || action === "skip") { } else if (action === "stop" || action === "skip") {
await stopSessionPlayback(session, true); await stopSessionPlayback(session, true);
} else if (action === "seek") { } else if (action === "seek") {