fix(player): resume a transcoded video by seeking, not by asking for a stream that starts mid-item
🏗️ Build and Test JellyTau / Run Tests (push) Failing after 5m10s
🏗️ Build and Test JellyTau / Android Compile Check (push) Skipped
Publish Documentation / Build & publish docs to gitea-pages (push) Successful in 5m30s
Traceability Validation / Check Requirement Traces (push) Successful in 19s
🏗️ Build and Test JellyTau / Run Tests (push) Failing after 5m10s
🏗️ Build and Test JellyTau / Android Compile Check (push) Skipped
Publish Documentation / Build & publish docs to gitea-pages (push) Successful in 5m30s
Traceability Validation / Check Requirement Traces (push) Successful in 19s
A resumed transcode played nothing at all: every segment came back 400, hls.js exhausted its retries and gave up, while the same episode from the beginning was fine. Jellyfin builds each segment URI by echoing the master playlist's query string into it, and its segment handler opens by rejecting any request carrying StartTimeTicks > 0 (ArgumentException → 400). So one resume position on the playlist is copied onto every hls1/main/N.ts and 400s all of them — the `> 0` being exactly why starting from the beginning survived. HLS does not need the parameter: a playlist spans the whole item and asking for segment N *is* the seek. It is removed from the URL builder entirely rather than conditionalised — the builder cannot know whether its response will be segmented — and the position becomes a seek issued once the player has loaded. The progressive /Audio/universal builder behind the background-audio handoff has no segments and keeps its StartTimeTicks, which is why audio-only handoffs resumed correctly and video ones did not. Completing that across the boundary, since the URL no longer starts where the caller asked: - reloadSource(url, position) now means "reload and resume AT this absolute position": it seeks the element once the source is playable and clears the transcode offset to zero. It previously set the offset to the position and seeked nothing, which was correct only while the URL itself began there — left in place it would have shown 20:00 on the scrubber while the opening titles played, with no seek ever happening. - The transcoded resume path in the player page collapses into the same "seek after load" branch direct streams already used. - VideoPlayer's background-audio return does the same: no base, seek to the absolute position. - The stale test asserting StartTimeTicks is present is rewritten to keep its other half (an HLS master playlist, never a progressive stream.mp4, carrying the chosen source and audio track). TRACES: UR-004, UR-005, UR-019, UR-021, UR-074 | DR-181 | UT-182, UT-183
This commit is contained in:
@@ -1514,10 +1514,16 @@ async repositoryGetPlaybackInfo(handle: string, itemId: string) : Promise<Playba
|
||||
return await TAURI_INVOKE("repository_get_playback_info", { handle, itemId });
|
||||
},
|
||||
/**
|
||||
* Get video stream URL with optional seeking support
|
||||
* Get a video stream URL.
|
||||
*
|
||||
* There is no start-position parameter on purpose: the URL is an HLS playlist
|
||||
* covering the whole item, and a position on it makes the server reject every
|
||||
* segment with `400` (DR-181). Callers resume by seeking after load.
|
||||
*
|
||||
* TRACES: UR-004 | DR-181 | UT-182
|
||||
*/
|
||||
async repositoryGetVideoStreamUrl(handle: string, itemId: string, mediaSourceId: string | null, startTimeSeconds: number | null, audioStreamIndex: number | null) : Promise<string> {
|
||||
return await TAURI_INVOKE("repository_get_video_stream_url", { handle, itemId, mediaSourceId, startTimeSeconds, audioStreamIndex });
|
||||
async repositoryGetVideoStreamUrl(handle: string, itemId: string, mediaSourceId: string | null, audioStreamIndex: number | null) : Promise<string> {
|
||||
return await TAURI_INVOKE("repository_get_video_stream_url", { handle, itemId, mediaSourceId, audioStreamIndex });
|
||||
},
|
||||
/**
|
||||
* Get audio stream URL for a track
|
||||
|
||||
@@ -409,23 +409,26 @@ describe("RepositoryClient", () => {
|
||||
handle: "test-handle-123",
|
||||
itemId: "item123",
|
||||
mediaSourceId: null,
|
||||
startTimeSeconds: null,
|
||||
audioStreamIndex: null,
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* There is no start-position argument: a position on the HLS playlist makes
|
||||
* the server reject every segment behind it with 400, so resume and seek are
|
||||
* performed by seeking the player after load (DR-181).
|
||||
*/
|
||||
it("should get video stream URL with options", async () => {
|
||||
const mockUrl = "https://server.com/Videos/item123/stream.mp4?start=300&api_key=token";
|
||||
const mockUrl = "https://server.com/Videos/item123/stream.mp4?api_key=token";
|
||||
(invoke as any).mockResolvedValueOnce(mockUrl);
|
||||
|
||||
const url = await client.getVideoStreamUrl("item123", "source456", 300, 0);
|
||||
const url = await client.getVideoStreamUrl("item123", "source456", 0);
|
||||
|
||||
expect(url).toBe(mockUrl);
|
||||
expect(invoke).toHaveBeenCalledWith("repository_get_video_stream_url", {
|
||||
handle: "test-handle-123",
|
||||
itemId: "item123",
|
||||
mediaSourceId: "source456",
|
||||
startTimeSeconds: 300,
|
||||
audioStreamIndex: 0,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -213,17 +213,25 @@ export class RepositoryClient {
|
||||
return commands.repositoryGetAudioStreamUrl(this.ensureHandle(), itemId);
|
||||
}
|
||||
|
||||
/**
|
||||
* A video stream URL, which always begins at the **start of the item**.
|
||||
*
|
||||
* There is deliberately no position parameter: the URL is an HLS playlist, and
|
||||
* a start position on it makes Jellyfin reject every segment behind it with
|
||||
* `400` (DR-181). Resume and transcoded seeking are performed by seeking the
|
||||
* player once the stream has loaded.
|
||||
*
|
||||
* TRACES: UR-004 | DR-181 | UT-182
|
||||
*/
|
||||
async getVideoStreamUrl(
|
||||
itemId: string,
|
||||
mediaSourceId?: string,
|
||||
startTimeSeconds?: number,
|
||||
audioStreamIndex?: number
|
||||
): Promise<string> {
|
||||
return commands.repositoryGetVideoStreamUrl(
|
||||
this.ensureHandle(),
|
||||
itemId,
|
||||
mediaSourceId ?? null,
|
||||
startTimeSeconds ?? null,
|
||||
audioStreamIndex ?? null
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1612,14 +1612,19 @@
|
||||
// Determine the target URL + how the element/offset should be positioned.
|
||||
let targetUrl: string;
|
||||
if (needsTranscoding && onSeek) {
|
||||
// Transcoded HLS can't seek by setting currentTime — the stream must be
|
||||
// rebuilt at the new position (StartTimeTicks). onSeek returns that URL.
|
||||
// The reloaded segment's timeline starts at 0, so seekOffset carries the
|
||||
// absolute base and the element seeks to 0 (handled on canplay).
|
||||
// Transcoded HLS is rebuilt rather than seeked in place, but the rebuilt
|
||||
// stream starts at the BEGINNING of the item, not at `pos`: a start
|
||||
// position on an HLS playlist is copied onto every segment URI and
|
||||
// rejected with 400 (DR-181). So there is no base to carry — the element
|
||||
// is seeked to the absolute position on canplay, exactly like a direct
|
||||
// stream. This previously set seekOffset = pos, which paired with a URL
|
||||
// that really did start there; leaving it would now display `pos` while
|
||||
// playing the opening titles.
|
||||
// TRACES: UR-040, UR-004 | DR-181
|
||||
targetUrl = await onSeek(pos, selectedAudioTrackIndex ?? undefined);
|
||||
seekOffset = pos;
|
||||
seekOffset = 0;
|
||||
currentTime = pos;
|
||||
pendingForegroundSeek = 0;
|
||||
pendingForegroundSeek = pos;
|
||||
} else {
|
||||
// Direct stream: reload the original URL and seek the element to pos.
|
||||
targetUrl = streamUrl;
|
||||
|
||||
@@ -192,13 +192,57 @@ describe("Html5PlayerAdapter", () => {
|
||||
|
||||
// Allow the internal 100ms settle delay, then fire canplay to resume.
|
||||
await new Promise((r) => setTimeout(r, 110));
|
||||
expect(bridge.setSeekOffset).toHaveBeenCalledWith(120);
|
||||
expect(bridge.setStreamUrl).toHaveBeenCalledWith("http://new/master.m3u8");
|
||||
video._fire("canplay");
|
||||
video._fire("seeked");
|
||||
await p;
|
||||
expect(video.play).toHaveBeenCalled(); // resumed because it was playing
|
||||
});
|
||||
|
||||
/**
|
||||
* The reload lands the viewer at the position they asked for — by *seeking*,
|
||||
* with no transcode offset left over.
|
||||
*
|
||||
* This used to be inverted: the offset was set to the position and nothing
|
||||
* seeked, which was right only while the reloaded URL itself began there via
|
||||
* `StartTimeTicks`. DR-181 removes that parameter, because on an HLS playlist
|
||||
* the server copies it onto every segment URI and then rejects each one with
|
||||
* `400`. With the URL starting at the item's zero, the old arithmetic leaves
|
||||
* `currentTime = offset + 0` — the scrubber reading 20:00 over the opening
|
||||
* titles, and the seek silently never happening.
|
||||
*
|
||||
* TRACES: UR-004, UR-005 | DR-181 | UT-183
|
||||
*/
|
||||
it("reloadSource() seeks to the position and clears the transcode offset", async () => {
|
||||
video.paused = false;
|
||||
const p = adapter.reloadSource("http://new/master.m3u8", 1200);
|
||||
|
||||
await new Promise((r) => setTimeout(r, 110));
|
||||
expect(bridge.setSeekOffset).toHaveBeenCalledWith(0);
|
||||
expect(bridge.setSeekOffset).not.toHaveBeenCalledWith(1200);
|
||||
|
||||
// Nothing may seek before the new source is playable — the element drops it.
|
||||
expect(video.currentTime).not.toBe(1200);
|
||||
|
||||
video._fire("canplay");
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
expect(video.currentTime).toBe(1200);
|
||||
|
||||
video._fire("seeked");
|
||||
await p;
|
||||
expect(video.play).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
/** A reload to the very start has nothing to seek to; it must not stall. */
|
||||
it("reloadSource() at position 0 does not wait for a seek", async () => {
|
||||
video.paused = false;
|
||||
const p = adapter.reloadSource("http://new/master.m3u8", 0);
|
||||
await new Promise((r) => setTimeout(r, 110));
|
||||
video._fire("canplay");
|
||||
await p; // resolves without any "seeked" event
|
||||
expect(video.play).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
/**
|
||||
* A reload that never becomes playable must be reported as a failure. It used
|
||||
* to resolve on the timeout, so a quality switch whose new stream the server
|
||||
@@ -227,6 +271,7 @@ describe("Html5PlayerAdapter", () => {
|
||||
const p = adapter.reloadSource("http://new/master.m3u8", 30);
|
||||
await new Promise((r) => setTimeout(r, 110));
|
||||
video._fire("canplay");
|
||||
video._fire("seeked");
|
||||
await p;
|
||||
expect(video.play).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -150,16 +150,29 @@ export class Html5PlayerAdapter implements PlayerAdapter {
|
||||
}
|
||||
|
||||
/**
|
||||
* PRIMITIVE: compound reload — the invariant HTML5 sequence to swap the source
|
||||
* and resume at `offset`. Contains NO strategy decision; the backend already
|
||||
* decided to reload and supplied the url/offset. Preserves the hard-won
|
||||
* dual-audio teardown and canplay wait.
|
||||
* PRIMITIVE: compound reload — swap the source and resume at
|
||||
* `positionSeconds`, an **absolute** position on the item's own timeline.
|
||||
* Contains NO strategy decision; the backend already decided to reload and
|
||||
* supplied the url/position. Preserves the hard-won dual-audio teardown and
|
||||
* canplay wait.
|
||||
*
|
||||
* The position is reached by *seeking the element*, and the transcode offset
|
||||
* is cleared to zero. It used to be the other way round — the offset was set
|
||||
* to the position and nothing seeked — which was correct only while the
|
||||
* reloaded URL itself began there, via `StartTimeTicks`. DR-181 removes that
|
||||
* parameter (on an HLS playlist it makes the server reject every segment with
|
||||
* `400`), so a reloaded stream now always starts at the beginning of the item.
|
||||
* Leaving the old arithmetic in place would have left `currentTime` reading
|
||||
* `offset + 0` — the scrubber showing 20:00 while the opening titles play, and
|
||||
* no seek ever happening.
|
||||
*
|
||||
* TRACES: UR-004, UR-005 | DR-181 | UT-183
|
||||
*/
|
||||
async reloadSource(url: string, offset: number): Promise<void> {
|
||||
async reloadSource(url: string, positionSeconds: number): Promise<void> {
|
||||
const el = this.element;
|
||||
if (!el) {
|
||||
// Still update the stream URL so the component's HLS $effect can pick it up.
|
||||
this.bridge.setSeekOffset(offset);
|
||||
this.bridge.setSeekOffset(0);
|
||||
this.bridge.setStreamUrl(url);
|
||||
return;
|
||||
}
|
||||
@@ -171,7 +184,8 @@ export class Html5PlayerAdapter implements PlayerAdapter {
|
||||
el.load();
|
||||
}
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
this.bridge.setSeekOffset(offset);
|
||||
// The reloaded stream begins at the item's zero, so there is no base to add.
|
||||
this.bridge.setSeekOffset(0);
|
||||
this.bridge.setStreamUrl(url);
|
||||
// A source that never becomes playable is a failed reload, not a slow one:
|
||||
// the caller (quality switch, transcoded seek) has to know so it can revert
|
||||
@@ -181,6 +195,13 @@ export class Html5PlayerAdapter implements PlayerAdapter {
|
||||
if (!ready) {
|
||||
throw new Error(`Reloaded stream never fired "canplay" within 10000ms`);
|
||||
}
|
||||
// Now that the new source is playable, put it where the caller asked for.
|
||||
// Seeking before `canplay` is dropped by the element, which is why this
|
||||
// follows the wait rather than riding along with the URL swap.
|
||||
if (positionSeconds > 0) {
|
||||
el.currentTime = positionSeconds;
|
||||
await this.waitForEvent(el, "seeked", 2000);
|
||||
}
|
||||
if (wasPlaying) await el.play();
|
||||
}
|
||||
|
||||
|
||||
@@ -152,6 +152,9 @@ async function seekVideo(
|
||||
)) as any;
|
||||
// Serde keeps these snake_case (only the "strategy" tag is camelCase).
|
||||
if (response.strategy === "reloadStream") {
|
||||
// `seek_offset` is the ABSOLUTE position to resume at, not a base to add to
|
||||
// the element's clock: the reloaded stream starts at the item's zero since
|
||||
// DR-181, so reloadSource seeks there. (The name is the wire field's.)
|
||||
await adapter.reloadSource(response.new_url ?? "", response.seek_offset ?? positionSeconds);
|
||||
} else {
|
||||
await adapter.seekElement(response.position ?? positionSeconds, 0);
|
||||
|
||||
Reference in New Issue
Block a user