mpv now decodes video on Linux, drawn into a framebuffer we own and blitted
into the default vbox's draw handler. Tauri's widget tree is untouched, so an
upgrade that assumes its own layout cannot invalidate this. Direct play means
the original file, hardware decoding, and no server transcode at all — where
previously every desktop video was re-encoded to h264 for the browser engine,
whatever the file actually was. Off by default: JELLYTAU_NATIVE_VIDEO=1.
That settles finding 2 of playback-backend-unification.md — "native video
cannot be composited with a Tauri webview" — by demonstration rather than
argument, on X11 and Wayland both.
Turning it on exposed nine defects, none of them mpv's. Each was the same
mistake in a different place: a capability written down as a compile-time fact
about the platform, or a state asserted instead of confirmed.
DR-238/246 a seek routed by the stream's container rather than by what the
engine could do with it - correct only while one player handled
those streams, silent the moment another did
DR-239 a property handled but never observed, so the play/pause button
waited for an event that could not arrive
DR-240 fullscreen expanding the document while the window stayed put
DR-241 a seek issued before the engine had a file, failed, and discarded
- which is why resume began at zero
DR-247 a Linux-only gate outliving the caller that made it Linux-only,
breaking the Android build outright
DR-250 a stop aimed at whichever renderer bookkeeping believed was in
charge, missing the one actually making sound
DR-251 a duration of zero believed, leaving the seek bar no scale
DR-252 a junk float converted to a Duration, panicking the backend the
instant a length-less stream appeared
So the MediaPlayer contract (DR-242 … DR-247): `open` carries a start position,
so no caller sequences load-then-seek and none can race an engine's load;
`seek` states a destination and leaves in-place-versus-re-open to the engine;
`snapshot` is one coherent read; and `Phase::Opening` names the window where
intent used to be lost. One conformance suite runs against every engine —
FakePlayer and mpv under cargo test, ExoPlayer instrumented on a device — so an
engine is either correct or visibly failing.
Two of the nine were introduced during this work and caught on hardware, not by
any suite: an over-broad capability that grouped ExoPlayer with mpv, and the
Duration panic. The suites test engines that behave. That is recorded in
docs/native-player-verification.md, which asks for the exact action sequences
that found them.
Verified: all automated gates, conformance (mpv 9/9, legacy 8/9 by design,
ExoPlayer 7/7 on device), and manual desktop and Android passes on real
hardware.
Known open and deliberately shipped: resume reads local progress and never the
server's; the background-audio handoff still declares a state swap it does not
confirm (the symptom is now impossible, the race is not); and `bun run
android:dev` builds an APK carrying the release application id, whose failure
message advises an uninstall that would destroy app data. Fix that last one
before anyone else builds for Android.
Squashed from worktree-linux-native-video, which keeps the per-defect history.
118 lines
4.5 KiB
TypeScript
118 lines
4.5 KiB
TypeScript
import type { StreamSelection } from "$lib/api/bindings";
|
|
/**
|
|
* NativePlayerAdapter — the Android/ExoPlayer PlayerAdapter implementation.
|
|
*
|
|
* ExoPlayer is driven entirely by the Rust backend (JNI), which already emits
|
|
* PlayerStatusEvents and handles seek/audio-track internally. So this adapter is
|
|
* a thin delegate to backend commands; there is no DOM element to touch and no
|
|
* hls.js. State reporting is unnecessary here because the native backend emits
|
|
* events directly — the adapter's job is only to forward control intents.
|
|
*
|
|
* NOTE: This adapter is currently unreachable — `createAdapter()` hardcodes the
|
|
* HTML5 kind, so Android video runs through Html5PlayerAdapter.
|
|
*
|
|
* That override was introduced citing tauri#10152 as an upstream blocker. That
|
|
* is no longer accurate: #10152 is a stale *feature request* (dead since
|
|
* 2024-07-01) asking that `transparent` not be desktop-only, and the capability
|
|
* shipped in tauri commit 27d01834 (2024-09-02). The related black/white-screen
|
|
* bug (tauri#8381, #9408) was a broken JNI signature for setBackgroundColor,
|
|
* fixed in wry 0.39.4; we ship wry 0.55.x.
|
|
*
|
|
* What is genuinely unproven is SurfaceView-behind-WebView *compositing* on
|
|
* Tauri Android — nothing upstream blocks it, and nothing upstream demonstrates
|
|
* it either. docs/architecture/05-platform-backends.md ("Native Video
|
|
* Compositing") describes the path that shipped.
|
|
*
|
|
* TRACES: UR-003, UR-005 | DR-004, DR-028
|
|
*/
|
|
|
|
import { commands } from "$lib/api/bindings";
|
|
import type { AdapterHost, PlayerAdapter, PlayerLoadOptions } from "./types";
|
|
|
|
export class NativePlayerAdapter implements PlayerAdapter {
|
|
readonly kind = "native" as const;
|
|
|
|
// Kept for symmetry / future reporting needs; the native backend emits events.
|
|
private host: AdapterHost;
|
|
private position = 0;
|
|
|
|
constructor(host: AdapterHost) {
|
|
this.host = host;
|
|
}
|
|
|
|
// The native surface is owned by the backend; nothing to attach in the DOM.
|
|
attach(_element: HTMLVideoElement | null): void {}
|
|
|
|
async load(_streamUrl: string, options: PlayerLoadOptions): Promise<void> {
|
|
// player_play_item already initiated native playback before this adapter is
|
|
// created, so there is no stream to load here — but it carries no start
|
|
// position, and ExoPlayer always begins at 0. The resume seek must be
|
|
// issued explicitly or "resume at position" silently plays from the top.
|
|
//
|
|
// Recording the position without seeking (what this used to do) is what
|
|
// broke Android resume: the frontend believed it had resumed while
|
|
// ExoPlayer played from the beginning.
|
|
//
|
|
// Live streams have no resume point — seeking one knocks the HLS window off
|
|
// its live edge, so they are excluded.
|
|
//
|
|
// TRACES: UR-005 | DR-004, DR-028
|
|
if (options.initialPosition > 0 && !options.isLive) {
|
|
this.position = options.initialPosition;
|
|
await commands.playerSeek(options.initialPosition);
|
|
}
|
|
}
|
|
|
|
async play(): Promise<void> {
|
|
await commands.playerPlay();
|
|
}
|
|
|
|
async pause(): Promise<void> {
|
|
await commands.playerPause();
|
|
}
|
|
|
|
async toggle(): Promise<boolean> {
|
|
const response = (await commands.playerToggle()) as any;
|
|
return response?.state === "playing";
|
|
}
|
|
|
|
/**
|
|
* PRIMITIVE: in-place seek. For the native backend, the backend drives
|
|
* ExoPlayer's seek internally, so this simply records the target position.
|
|
* (The decision to seek-in-place vs reload was already made by the backend.)
|
|
*/
|
|
async seekElement(positionSeconds: number, _offset: number): Promise<void> {
|
|
this.position = positionSeconds;
|
|
}
|
|
|
|
/**
|
|
* PRIMITIVE: reload source. For the native backend the backend already
|
|
* performed the reload+seek internally as part of the seek decision; nothing
|
|
* to do on the frontend beyond recording position.
|
|
*/
|
|
async reloadSource(_selection: StreamSelection, offset: number): Promise<void> {
|
|
this.position = offset;
|
|
}
|
|
|
|
setVolume(volume: number): void {
|
|
void commands.playerSetVolume(Math.max(0, Math.min(1, volume)));
|
|
}
|
|
|
|
setMuted(_muted: boolean): void {
|
|
void commands.playerToggleMute();
|
|
}
|
|
|
|
async selectSubtitle(streamIndex: number | null, arrayIndex?: number): Promise<void> {
|
|
const indexToUse = streamIndex === null ? null : (arrayIndex ?? streamIndex);
|
|
await commands.playerSetSubtitleTrack(indexToUse);
|
|
}
|
|
|
|
getPosition(): number {
|
|
return this.position;
|
|
}
|
|
|
|
async dispose(): Promise<void> {
|
|
// The backend is stopped via player_stop by the owning view; nothing to free.
|
|
}
|
|
}
|