Introduce PlayerAdapter contract; decision logic shared in Rust backend

Establish a decoupled player boundary so UI and backend interact with video
through one contract, with the HTML5 (Linux/interim-Android) and native
(ExoPlayer) providers as interchangeable primitive-executor adapters.

- PlayerAdapter interface + AdapterHost callback bag (adapters/types.ts): the
  adapter owns only decision-free element PRIMITIVES (seekElement, reloadSource,
  play/pause, setVolume, selectSubtitle); it never branches on strategy.
- Seek/audio-track DECISIONS stay in Rust (player_seek_video / _switch_audio_track
  return a strategy); the facade dispatches the chosen primitive to the active
  adapter. Both providers share the one decision path — logic lives once, in Rust.
- Facade holds the active adapter; a new ControlCommand PlayerStatusEvent lets
  backend control (lockscreen/remote/sleep) drive the webview <video> element.
- Html5PlayerAdapter resolves the LIVE element via the bridge (fixes play/pause
  silently no-opping when the element was re-bound).
- Do not emit a "stopped" player state on natural end-of-video: it flipped the
  player/mode to idle mid-handoff and suppressed next-episode auto-advance under
  a sleep timer. Jellyfin progress reporting is preserved; the backend's
  on_video_playback_ended owns the transition.
- VideoPlayer net -300 lines (strategy/HLS-reload logic relocated to the adapter).
- Adds 20 adapter unit tests; existing suites stay green (vitest 457, cargo 416).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-02 19:56:20 +02:00
co-authored by Claude Opus 4.8
parent 1f6977cd01
commit a64e1b1fb4
15 changed files with 1198 additions and 301 deletions
+10 -2
View File
@@ -451,7 +451,10 @@
savedProgress = null;
const id = itemId;
if (id) {
loadAndPlay(id, 0);
// forceRestart bypasses the resume-progress check; without it, passing a
// start position of 0 is treated as "no position" (`!startPosition`), which
// re-runs the resume check and re-shows this very dialog in a loop.
loadAndPlay(id, 0, true);
}
}
@@ -537,7 +540,12 @@
if (id) {
reportPlaybackStopped(id, positionSeconds);
}
html5Adapter.reportState("stopped", id ?? null);
// Intentionally do NOT emit a "stopped" player state here. This runs on both
// natural end-of-video (an autoplay handoff the backend's on_video_playback_ended
// owns) and on player close/unmount (where player_stop already drives the
// backend state). Emitting StateChanged{stopped} on natural end flips the
// player/mode to idle mid-handoff and suppresses next-episode auto-advance —
// the "sleep timer pauses at the end of an episode instead of continuing" bug.
}
async function handleVideoEnded() {