fix(player,reporting): report real positions, and count an audio-only episode as watched

Returning to the foreground before the background-audio stream had started
playing handed the frontend 0.0s, so the video reloaded at StartTimeTicks=0 —
the episode restarted from the beginning — and the stop report that followed
wrote that zero to Jellyfin as the resume point. Caught on device: locked at
18.4s, unlocked 3.5s later with ExoPlayer still IDLE.

The base that turns a handoff's relative timeline into the episode's is applied
once at the native tick boundary (DR-159), so before the first tick nothing has
applied it. The same blind spot covers webview-rendered media, where nothing is
loaded into the native backend at all and its position is a permanent 0 — which
is why 14 of 14 stop reports in a 35-minute trace were zeroes, one landing 40s
after the frontend had correctly reported 15:22 for the same episode.

- absolute_position(): the maximum of the backend's reading, the last position
  webview media reported, and the handoff base. Exact rather than heuristic —
  at most one term is ever meaningful, and the base is a floor the stream
  cannot physically be behind. duration() gains the same fallback.
- Withhold zero-position stop reports. A zero is never information, and
  Jellyfin stores the reported position as the resume point, so sending one
  only ever destroys a real one.
- Report progress from the controller's own position ticks, through the 30s
  throttler it already shared with the native audio path.
  /Sessions/Playing/Progress was previously requested zero times in 35 minutes.
- Report a finished audio-only episode stopped at its runtime before advancing,
  so Jellyfin's 90% rule marks it played. Nothing else can: the webview is
  suspended and its <video> was torn down at the handoff.
- Split the handoff by source — a downloaded file takes no base and a real
  seek, a stream keeps its StartTimeTicks base and no seek — and stop routing a
  downloaded handoff's absolute seek through the stream rebuild, which refuses
  a non-remote source outright.

Reports go through a PlaybackReportSink, which also collapses three copies of
spawn-a-task-and-hope into one and is what let each of these be written as a
failing test first.

TRACES: UR-005, UR-025, UR-040, UR-071 | DR-178, DR-179, DR-180 |
        UT-176, UT-177, UT-178, UT-179, UT-180, UT-181
This commit is contained in:
2026-08-16 10:23:00 +02:00
parent 5096c01960
commit de1c13e72f
4 changed files with 853 additions and 129 deletions
+17 -8
View File
@@ -13,12 +13,15 @@ import { commands } from "$lib/api/bindings";
import { auth } from "$lib/stores/auth";
/**
* Report playback start to Jellyfin (or queue if offline)
* Record the start of playback **locally**, with the context it started from.
*
* The Rust backend handles both local DB updates and server reporting,
* automatically queueing for sync if the server is unreachable.
* The server is told by Rust: loading an item into the controller reports the
* start, carrying the position the stream actually begins at (zero for an
* ordinary play, the handoff point for a background-audio stream). What this
* adds is the context — which album or series the play came from — which only
* the local DB keeps.
*
* TRACES: UR-005, UR-025 | DR-028
* TRACES: UR-005, UR-025 | DR-028, DR-179
*/
export async function reportPlaybackStart(
itemId: string,
@@ -50,12 +53,18 @@ export async function reportPlaybackStart(
}
/**
* Report playback progress to Jellyfin (or queue if offline)
* Record playback progress **locally**.
*
* Note: Progress reports are frequent and are not queued for sync.
* The final position is captured by reportPlaybackStopped.
* The server's copy is not sent from here. Position ticks already flow into Rust
* through the player adapter (`player_report_position`), and the controller
* reports them onward on a 30s throttle — one place that covers webview video,
* native audio and the background-audio handoff alike, instead of a second
* frequent IPC path racing it.
*
* TRACES: UR-005 | DR-028
* This function is therefore the *local* half only, which is what its caller
* needs for resume points that work offline.
*
* TRACES: UR-005 | DR-028, DR-179
*/
export async function reportPlaybackProgress(
itemId: string,