Commit graph

216 commits

Author SHA1 Message Date
cd45745822 player: folding the overlay does not unpause
The fold-from-the-title un-paused the video ("keep watching", the first
cut's reading) — the follow-up on issue #59 says a paused video must
STAY paused when the overlay folds. The dismissal now only folds and
returns the focus to the surface; play state stays exactly as it was.
2026-11-07 05:59:10 +00:00
b3a6bd0e5c player: the subscribe check takes the channel handle, not the video id
The engagement hoist's first cut handed the subscribe toggle the VIDEO's
UUID where it wants the CHANNEL handle — subscriptionExists failed, the
subscribed state never arrived, and the pill stayed in its dimmed
"Checking…" grey instead of ever turning red (follow-up on the flicker
fix).
2026-11-07 05:56:47 +00:00
213c7ba4a7 player: engagement state lives with the video; the fold stays folded
Two follow-ups on the player feedback.

The subscribe pill claimed "not subscribed" for a moment on every
pause — and switched over to red as soon as the server answered. The
state (subscription toggle, my rating, the optimistic like/dislike
counts) lived inside the overlay composable, which unmounts on every
hide, so every pause refetched from nothing and the wrong state showed
while waiting. It now lives with the video: the subscribe toggle is
created when the video opens and survives overlay shows and hides, the
rating fetch runs once, and the counts keep their optimistic updates.
While the state is still unknown the pill dims and says "Checking…"
instead of confidently claiming the opposite.

And UP-from-the-title folded the overlay only to open it again
instantly: the fold consumed the DOWN of that press, but its trailing
ACTION_UP landed in the surface's reveal branch and undid the
dismissal. The fold marks itself, and the surface swallows exactly that
one trailing UP.

Addresses issue #59 feedback, and the subscribe-flicker report on the
paused overlay.
2026-11-07 05:52:26 +00:00
6eaac08df6 player: the comments close lands on the bar, and UP from the title folds it
Two TV feedback reports on the player's focus flow.

Closing a sidebar while playing hid the overlay, so the pill that had
opened it was no longer composed — its focus request failed silently
and the focus wandered onto the invisible list cards underneath, where
OK played a video nobody saw (issue #58). closeSidebar now decides by
state, not by chance: overlay up means the opener pill exists and gets
the focus back; overlay hidden means the sidebar had swallowed it, and
the bar comes back revealed instead — the D-pad scrubs again.

While paused there was no way to fold the info overlay at all (issue
#59): one UP past the title now closes it and keeps watching — the
video plays again, controls gone. Sideways from the title stays put, as
before.

Addresses #58, and #59.
2026-11-07 05:43:32 +00:00
3ef20c679a player: chapter names on the seek bar, ticks toned down
Two pieces of issue #52 feedback from the TV look.

The ticks were loud white and drew the eye away from the played part:
they are half-white now, separators instead of exclamation marks.

The chapter names were invisible entirely. While the controls overlay
is up, the row above the seek bar names what is playing — index in
amber, title in white, live with the position ("2 of 3 — Middle") —
and the scrub preview panel carries the chapter title under the target
time. TalkBack named chapters already (the bar's state description);
now everyone else sees them too.

A UI test asserts the label against the fake's chapters, and the
screenshot fake (tools/mock) learns the same chapters/captions/
storyboard routes FakePeertube serves, with the sprite generated in
plain Python — one fake world, two servers, as the screenshot skill
puts it.

Addresses #52 feedback. Chapter JUMPING stays out: on a D-pad it needs
a home of its own (a chapters sidebar or a scrub step mode) and the
issue itself calls it optional.
2026-11-07 05:07:11 +00:00
c1703a214c login: make the logging-in veil opaque
The 80 %-black veil let the Sign in button's own spinner shine through
next to the veil's spinner — a double spinner, and the form showing
through underneath (issue #56 feedback). Full black now.

Addresses #56 feedback.
2026-11-07 04:39:26 +00:00
b36dfcdd1e login: the login talks: black, centered, "Logging in ···"
On the TV, a phone submit or the Sign in press left the screen exactly
as it was — the only change was a spinner on the Sign in button, which
sat behind the on-screen keyboard (issue #56 feedback: "it's not
obvious I'm logging in").

Now two things happen on a login attempt: the keyboard closes, and the
screen turns black with a centered spinner and the words "Logging in
···" — the state the user asked for. It lives while the request runs;
a failure drops the veil and the honest error returns to the field.

The phone submit's field updates also move to the main thread (the
server calls in from its own thread — Compose snapshots tolerate that,
but the keyboard call wants the UI thread).

Addresses #56 feedback.
2026-11-07 04:34:32 +00:00
5586d23719 login: the phone page earns its CSS
The served form page overflowed sideways (inputs with width:100% plus
padding and no box-sizing — the double scrollbar), had no logo, and one
uncaught parse exception in a malformed POST took the whole phone
server down with it.

The page is rebuilt with the mobile rules of thumb: box-sizing on
everything, a header with the TV logo inline, thumb-sized controls, url
autofill hints, and no horizontal scroll anywhere. serve() can no
longer throw — a bad request answers "try again" instead of killing
NanoHTTPD's accept loop.

Verified end to end on the emulator: GET renders the styled page, a
POST fills the TV's fields and starts the sign in, a missing-field POST
answers kindly.

Part of #56 feedback.
2026-11-07 04:25:41 +00:00
b76b5fd724 login: two panels instead of a floating giant QR
The login looked improvised: a huge white QR square floating to the
right of a cramped form, with dead space under it (issue #56 feedback:
"nicer looking", "the form is too cramped", "research how other apps
do logins on TV").

The screen now follows the two-route shape YouTube and Netflix use:
two side-by-side cards, both introduced by what they are. The left
card is the remote route (instance URL, username, password with the
eye toggle, Sign in); the right card is the phone route, with the QR
at a readable 140 dp, the form address printed under it for cameras
that fail, and the status line that says what is going on. Same
heights, same paddings, same background tone — the screen reads as
one design instead of two accidents.

The form stays out of the keyboard's way; the phone form server keeps
its one-page-one-POST lifetime.

Addresses #56 feedback.
2026-11-07 03:04:56 +00:00
df43142329 login: the QR carries the login form, not just an address
Three rounds of issue #56 feedback.

The QR no longer mirrors the URL field per keystroke (why would it
change?), and the joinpeertube.org placeholder no longer looks like a
recommended address. The code now points at the login form itself: the
device serves a tiny dark page over the home network (NanoHTTPD, one
GET and one POST, running only while the login screen is up), the phone
opens it, fills instance URL + username + password, and the TV's fields
fill and sign in on receive. No dpad typing anywhere unless the person
chooses the manual route.

The address is printed UNDER the QR in plain text for cameras that fail
— the old caption ("Waiting for your phone…") said nothing usable —
and the panel sits at the screen's right edge, where the floating
keyboard leaves room even while a field is focused; with the tightened
form the Sign in button also clears the keyboard entirely.

The keyboard finally lifts the form: android 15 enforces edge-to-edge
and the window's IME insets never reached Compose — the window is now
explicitly decor-fits=false, so imePadding() gets real values.

The QR stays via zxing core; the form server is NanoHTTPD (a single
~50 KB jar, no transitive dependencies). All traffic stays on the home
network: the page travels from the TV to the phone and back.

Verified on the emulator end to end: GET renders the form, POST fills
the TV's fields and starts the sign in ("Received from your phone ✓"),
wrong passwords surface the honest error.

Addresses #56 feedback.
2026-11-07 02:28:20 +00:00
6631099164 login: logo, compact top form, honest QR, no paste buttons
The first screen a new user sees (issue #56) had its password and Sign
in covered by the on-screen keyboard, three text-only paste buttons
nobody can operate with a remote, a pre-filled URL of one specific
instance, and no branding at all.

The screen is rebuilt: TV icon + name at the top, the three fields and
Sign in below, all top-aligned so the keyboard covers nothing during
typing; the URL starts empty with a placeholder to signal "this project
speaks to any PeerTube"; the paste buttons are gone and Show password
became an eye icon in the field; DOWN now reaches Sign in from the
password. A QR panel beside the form mirrors the URL while typing:
scanning it opens the instance on a phone, where new users create their
account before signing in on the TV. Real phone-mediated login needs a
device-authorization flow PeerTube's OAuth does not offer, so the QR
points at the instance's own web presence — the layout keeps the space
for the real thing and stays compatible with multi-user login later
(plain fields, no assumptions about who is already storing tokens).

The QR is generated with zxing's core module (single 600 KB jar, no
transitive dependencies), the smallest dependency that earns its keep
against drawing QR from scratch.

Addresses #56's concrete asks; QR-mediated login and multi-user stay
open on the issue.
2026-11-07 01:51:18 +00:00
75305e3f62 search: one type row with the mic inline, compact filters, no Search pill
The search header had grown to half the screen, and its red was saying
two things at once (issue #57): the active chip and a focused chip had
the same fill.

The field now shares its row with the mic button, the way other apps
pair them: the remote's mic key lands here too, RIGHT moves to Voice
and Voice hands focus back or down to the filters. The Search pill is
gone — OK on the field triggers the search action, which the screen's
keyboard wiring already did. The two filter rows stay (Videos/Channels
answers WHAT, Local/Vidiverse answers WHERE, per the #38 review) but at
roughly half height: 4 dp padding instead of 7.

Chip colors: focus is white with dark text, active is the red fill,
and a focused chip that is also active gets a red border, so the two
states can no longer be confused.

The two search-driven tests move to performing the field's search IME
action, which is exactly the user gesture that replaced the button.

Addresses #57 (the concrete asks; a bigger UX pass can build on this).
2026-11-07 01:51:18 +00:00
cc5c484480 player: the preview answers at once, and only while actually scrubbing
Two pieces of TV feedback on #51.

A brief pause or play showed the picture floating over the frozen
frame: the play/pause toggle on the bar pulsed the scrub state. The
pulse is arrow-presses only now; the toggle still restarts the overlay
hide countdown, so the controls stay while the user uses them.

And the video's first seconds scrubbed blind: the preview needs the
decoded storyboard sprite, which on a TV arrives ~3 s after the video
does. The storyboard fetch now starts the moment the player has a uuid,
in parallel with the detail call instead of after it, and the preview
panel holds the picture's slot open and shows the target time at once —
the picture pops in when it decodes, usually within a second or two.

Emulator suite green (SeekBarChaptersPreviewTest drives the preview
panel end to end).

Addresses #51 feedback.
2026-11-06 23:19:35 +00:00
185397980f player: chapters, captions and sprites follow the video's own server
The Linux Experiment's newest episodes carry chapters — on tilvids.com,
not here. PeerTube keeps chapters and captions instance-local: nothing
of them federates, so our instance's metadata routes answer empty for
every federated video, and a foreign-resolved video was only ever
listed by its host. The seek bar stayed chapterless exactly on the
videos where it would matter most.

The metadata fetches now go to the host the video lives on: foreign
playback asks the origin directly, and for locally-resolved federated
videos an empty local answer falls back to the detail channel's host.
The sprite warm-up rides along, so scrub previews appear on foreign
videos too.

Emulator suite green (the two known real-instance 429 flakes pass in
isolation); RemotePullIntoHistoryTest drives the foreign-present path
of the same wiring.

Addresses #52 (the Linux Experiment chapters), and #53/#51 on foreign
videos.
2026-11-06 09:07:25 +00:00
fb7a68eb3e player: scrub preview answers the TV — reveal on the first seek, warm sprite
The TV session for #51/#52 surfaced three seams the emulator's instant
network hid.

The first seek while playing went to the surface's handler, which
seeked blindly: the overlay stayed hidden and the user could not see
where the position went. The first seek press now reveals the bar,
moves focus into it (through a retrying request — a plain requestFocus
races the bar's first composition and loses, leaving the whole overlay
focusless), and pulses the scrub: the next presses ride the bar with
the preview.

The preview's stay-up window belongs to the surface now. On this TV the
keys keep arriving at the surface's handler even when the bar holds the
compose focus, so a preview gated on the bar's own state never lit up.
One pulse, one fold timer, both paths feed it.

The sprite downloads only after the first scrub and this TV's Wi-Fi
needs ~3.5 s for the 1 MB jpg — the whole preview window was over
before the picture arrived. The player decodes it while the video
plays, and the bar starts from the warm copy. A metadata route that
answers 429 mid-walk took the chapters and the preview down with it;
they retry once a beat later.

TV-verified: preview shows at the scrub position from the first press
onward, chapters still draw, playback and resume unchanged.

Addresses #51, and #52's TV side.
2026-11-06 01:49:41 +00:00
fdec37a2a6 player: subtitles from the video's captions, with a global language (#53)
PeerTube exposes per-video caption tracks (a live-verified
/videos/{uuid}/captions route returning WebVTT URLs); they now travel
with the media item as SubtitleConfigurations, so Media3's text
renderer picks a track and the app draws the cues above the video once
the controls overlay is hidden. Private media get the file token on
their caption file like on their segments.

The action row gains a Captions pill (only on videos that carry
tracks): Off -> each available language -> Off, the label telling an
instance-generated "(auto)" track. Every chosen language lands on top
of a persisted MRU list in the token store, and the choice applies
GLOBALLY: the next video plays with the last chosen language on, which
is the per-video-never behavior #53 asked for. The pill is announced
by TalkBack as its state flips (liveRegion from #54).

The fake backend serves one auto-generated English track and a cue
every 10 s; SubtitleCycleTest drives Off -> English -> Off and asserts
the NEXT video opens with the remembered language on. Actual cue
rendering needs bytes to play (the fake's media is a 404) and is
verified on the TV below.

Addresses #53.
2026-11-06 01:06:37 +00:00
9933a74459 search: speak the query with the remote's mic (#55)
Android TV's speech recognition is a system overlay, not an API you own:
the app asks it for results (RecognizerIntent) and takes the best guess
into the field. The Search header gets a "Voice" chip at the end of the
kind row, and the remote's mic key (KEYCODE_VOICE_ASSIST) plus SEARCH
fire the overlay from the field too — several remotes hand it to the
focused app rather than the assistant. When no recognizer exists the
chip says so instead of dying.

Addresses #55.
2026-11-06 01:06:37 +00:00
bd71567bc6 drawer: offer and stage self-updates from the release feed (#49)
The drawer gains an "Update to vX" row, pinned above Exit (issue #49).
It checks the release feed once per drawer open: the newest Forgejo
release against this APK, preferring the versionCode the release script
writes into the description, falling back to tag semver. No releases,
or nothing newer, is honestly nothing to do.

One click streams the APK into the app cache with a percentage on the
row; the next click hands the staged file to the system installer
behind a FileProvider grant. REQUEST_INSTALL_PACKAGES is requested so
first-time users reach the "allow installing unknown apps" prompt
instead of a dead end.

The feed URL sits on AppGraph so the fake-backend test can point it at
its own server: AutoUpdateDrawerTest drives row appears -> click ->
"Install vX", stopping short of the installer itself, which is system
UI.

Addresses #49.
2026-11-06 00:51:39 +00:00
ecedf67612 player: chapter ticks on the seek bar, and a preview over the scrub
Issues #52 and #51, both about the seek bar.

PeerTube's /videos/{uuid}/chapters route (verified live against 8.3.1)
drives bright 2 dp tick marks at every chapter start, drawn over both
the red played part and the dim track; the bar's TalkBack description
names the chapter the position sits in ("chapter 2 of 3"). The fake
backend serves chapters for every video, asserted by a new UI test via
the state description.

Scrubbing now floats a preview above the bar (issue #51): a frame from
the video's storyboard sprite (also a live-verified route,
/videos/{uuid}/storyboards) plus the target time, kept up while the
user keeps pressing and folded ~1.2 s after the last one. The sprite
decodes once and is cached; a frame is a cheap createBitmap per press.
Private media get the file token appended to the sprite URL.

The preview's fold runs on a wall-clock Handler, not a compose delay:
a compose delay only advances while frames are produced, and a still
video produces none — the preview would have stayed up forever.

The 5 s controls hide countdown also restarts on every bar press while
playing: mid-scrub the overlay used to fold away together with the
position line (the second half of #51).

Addresses #52, #51. Emulator suite green; the two remaining real-inst-
ance tests flaked on 429 in full-suite runs and pass when isolated.
2026-11-06 00:47:19 +00:00
510c99fa3f player: take the WebView P2P engine out again, the swarm is postponed
The WebView bridge cost more than it gave back. #50 landed Nov 3 and
four fix commits followed in two days over the seams of the bridge
alone; the p2pml library pinned okhttp {strictly 5.2.1}, whose classpath
clash killed the whole fake-backend test suite for two days (every test
died with NoClassDefFoundError before its first assertion), and the
engine set a toolchain floor (Kotlin 2.2, AGP 8.13, compileSdk 36,
Media3 1.8) plus +0.8 MB of APK for a library the emulator cannot even
run. A single playback session also carried a WebView, a Ktor loopback
server and a JS engine — the heaviest components Android has.

Playback is back to exactly the pre-#50 shape: origin/R2 streaming with
the file-token re-injection (#41) and the deep-buffer tuning (155edd0)
kept. The keeper work and the tuning from the #50 era (background token
fetch, buffered-range visibility, focus handback) all stay.

The implementation is preserved complete on branch p2p/webview-bridge,
including the byte-range research in docs/p2p.md and the upstream patch
in tools/p2p-core-patch/. The toolchain floor stays as it is — nothing
user-visible, and rolling it back risks more than it saves. A proper
implementation would be a native Kotlin WebRTC segment exchanger, not a
JS library in a WebView.

Postpones #50.
2026-11-05 23:47:55 +00:00
c6b20d444c ui: make the app readable by TalkBack on the TV
Android TV ships TalkBack, and it walks D-pad focus instead of touch,
so the focus-first lists were already half accessible — what was
missing were the labels: screens were navigable but silent.

Section headers (Home's rows, every feed page header, the Channels row
labels) now carry the heading() role, so a screen reader user can hop
heading to heading instead of stepping through every card. The player
seek bar names its position ("3:04 of 21:10") when focused instead of
speaking as an unlabeled sliver, and the Subscribe / Like / Dislike
buttons announce their flipped state as it changes via liveRegion, so
a successful toggle is heard without refocusing. Playback errors are
announced the same way. The card thumbnail no longer repeats the title
into the card's merged description, which made TalkBack say every
title twice.

No visual or D-pad behaviour changes anywhere.

Addresses #54. Tested on the emulator with the fake backend
(NavigationRegressionTest, PrivacyLetterVisibleTest,
SearchChannelsFilterTest pass; the pre-existing failures named in the
previous commit are untouched).
2026-11-05 23:38:29 +00:00
7744d0c45f tests: bump mockwebserver to OkHttp 5 so the fake-backend suite runs at all
Since P2P playback (#50) the p2pml engine pins okhttp {strictly 5.2.1},
and Gradle resolves the app's okhttp 4.12.x to that. mockwebserver
4.12.0 was built against OkHttp 4, whose okhttp3.internal.Util class
does not exist in 5.x — every fake-backend instrumented test died in
FakePeertube's constructor with NoClassDefFoundError before its first
assertion. Nobody noticed because the suite kept "failing": the whole
UI test gate has been dead since #50 landed.

The 5.x mockwebserver keeps the old okhttp3.mockwebserver API, so
FakePeertube needs no changes.

Surfacing a side effect: with tests running again, three tests fail
for real reasons that were invisible while the suite was dead —
WatchProgressEnrichmentTest (both), ExternalCardMarkTest
(vidiverseResultsAreMarkedAsComingFromElsewhere) and
SearchChannelsFilterTest (theChannelsFilterShowsChannelResults). They
reproduce without the #54 accessibility changes and need their own
investigation.

Addresses #54 (the accessibility changes below are only testable once
this runs).
2026-11-05 23:38:29 +00:00
a647599905 lists: never append the same video twice (crash on duplicate lazy keys)
The app crashed with `Key "v128858" was already used` in a LazyRow.

Every paged list appended pages blindly (`items + chunk`). PeerTube's lists are not
stable between pages: "Continue watching" is server-side history, so watching a video
moves it to the top; the next page, fetched at the old offset, can therefore contain a
video the list already holds. Two cards with the same key crash Compose's lazy list.

Items are now de-duplicated by a stable identity when a page is merged — videos by
short UUID, history entries by their video — keeping the first occurrence so the order
is untouched.
2026-11-05 21:55:43 +00:00
04a783485b player: reuse the detail the app already fetched for the progress bars
Opening a card waited ~2 s before anything happened. The cause was not a missing
prefetch: the detail call is already made for every card that appears in a list,
because the red progress line is drawn from its userHistory — the response was then
thrown away, and pressing the card fetched the same thing again.

Detail responses are now kept for two minutes and invalidated when playback exits (so
the resume position is never stale). Browsing a row and pressing a card costs no round
trip at all; the playout URL, tracker URLs and position are already there.
2026-11-05 21:47:46 +00:00
5094ed8246 player: keep no engine alive unless the viewer actually stops (#50)
Going back to the list felt laggy: the deferred engine teardown fired ~0.7 s later,
destroyed a WebView on the UI thread, and swallowed the first keypress of the next
navigation.

The engine is now created lazily — only when the video is playing, has run for at
least ten seconds, and the viewer pauses or it stalls. Those sessions never create a
WebView at all, so there is nothing to tear down later and navigation stays smooth.
When it does exist, the switch happens in that same quiet moment (a re-prepare while
paused), and a session that never pauses simply never joins the swarm.

Verified: builds, tests pass, playback starts from the origin as before with no
errors. The lazy boot needs one pause more than ten seconds into a video to trigger.
2026-11-05 21:34:39 +00:00
63ed43aef0 player: hand focus back before the overlay leaves, and fade it
Closing a video showed the row's first card selected for a moment before the card
actually watched was focused, then the row scrolled twice. Compose restores focus
along the trail of the focused node, and while the player overlay exists that trail
cannot reach the card — so focus fell to the row's first card and was corrected 600 ms
later.

The player now asks the card for focus (CardFocus registry) *before* it disappears,
so the trail ends at the card and focus never moves. The BACK effect in the row keeps
only the scroll, and only when the card is off screen. The overlay also fades in
(160 ms) and out (200 ms) instead of snapping, which makes the hand-over invisible
rather than merely fast.
2026-11-05 21:25:46 +00:00
dc0de5c468 player: stop stalling the start on the file token, and on engine teardown
Two reported symptoms, one cause each.

The video froze at "18%" while starting: the token is fetched lazily on the first
media request (which is right), but that request then waits for the round trip. It
is now fetched in the background as soon as the details are known — nobody waits,
and the value is there before the first request needs it.

BACK in the player paused for half a second before closing: the engine teardown
destroys a WebView and a Ktor server on the UI thread, right when the home screen
wants to animate in. It is deferred by 700 ms so the transition wins the thread.
2026-11-05 21:03:24 +00:00
7afff1a9be player: never hand playback to the swarm before it has started (#50)
Initial buffering counted as a "quiet moment", so the swarm switch fired immediately
at startup: a working direct stream was replaced by the bridge before it could serve,
and the video sat on the loading screen for over a minute on the TV.

The switch now requires the first frame and at least ten seconds of playback, on top
of the pause-or-stall condition. Verified on the TV afterwards: plays straight away,
engine ready in the background, no switch (nothing was paused), no playback errors.
2026-11-05 13:34:08 +00:00
6424ce8eda player: start fast, join the swarm in a quiet moment (#50)
The swarm engine was in front of every video: 2.4 s of blocked UI thread for the
WebView provider plus the core boot, on a TV that can start a video in under a
second. Playback now always begins from the origin, and the engine is moved into
the path only when doing so cannot be seen — during a stall, or while the user has
paused. That switch is a re-prepare, so it must never land while the picture moves.

Two supporting pieces:
- WebViewWarmUp loads the provider once, 1.5 s after the app starts (312-424 ms of
  work on the TV), so per-video engine creation no longer pays for Chromium;
- the file token is fetched lazily (already committed) instead of in front of
  playback.

Verified on the emulator: video plays immediately, engine ready in the background,
"moving playback onto the swarm at 51s" during a pause, then playback continues with
no errors. The TV measured the warm-up; the full flow still needs a real viewing
session there.
2026-11-05 13:03:06 +00:00
8bc08cb2fc player: fetch the file token when it is needed, not in front of playback
On the TV the token was 1.8 s of the startup: a full round trip before the video
could even be prepared, for a value only the first media request uses. That request
runs on a loader thread, where fileTokenForMedia() already fetches it on demand, so
the eager call in present() only added latency.

Measured on the TV: metadata 5765 -> 4234 ms from the card press.
2026-11-05 12:42:01 +00:00
27afe4111a player: drop the one-off startup instrumentation (#50)
The startup timing lines and the playlist read/repair timing were measurement
scaffolding: they existed to answer "where do the seconds go" once, and they do not
belong in the app. Removed, along with the now unused debug-log constant on the
engine. When the question comes back, a temporary log costs a minute — the tree
should not carry it in the meantime.
2026-11-05 12:29:01 +00:00
80cab8ac41 player: measure startup from the card press, not from the source setup (#50)
Every number quoted so far started the clock when the media source was requested,
i.e. after the metadata had already loaded — so the phase the user blames was
invisible. The timing now starts when the player screen opens (within a frame of
the card press) and also logs when the metadata arrives.

First honest end-to-end run on the emulator: metadata 537 ms, engine gate ~10 ms,
playlists ~20 ms, first frame at 3.48 s. The remaining ~2.9 s is software decoding
on the emulator, which is exactly the number that cannot be trusted here — the TV
decodes in hardware and prints the same four lines.
2026-11-05 12:28:29 +00:00
27a20779b0 player: boot the swarm while the metadata is still loading (#50)
The engine gate was always on the critical path: open a video, fetch its details,
then start a WebView, then ask for a playlist. All the engine needs is the swarm id
(the card already knows its uuid) and a tracker (every instance exposes
wss://<host>/tracker/socket), so it now starts the moment the player screen opens
and is ready before the playlist is requested.

Player and engine moved up from PlayerSurface to PlayerScreen for that reason:
waiting for the core is still required (the bridge cannot serve a playlist before
the WebView's port exists), but by then it has already happened.

Measured on the emulator with a card (uuid present): the gate dropped from
460-510 ms to ~10 ms, first frame 1.84-2.43 s against 2.16-2.62 s, no playback
errors. Deep links carry no uuid and keep the old path. Emulator numbers are noisy
because software decoding dominates; the TV numbers are the ones that matter and
need a free TV.
2026-11-05 11:43:14 +00:00
2689b38c77 player: do not ask the bridge for a playlist before it can answer (#50)
Chasing startup time, the engine gate was reduced to "wait for the local socket"
(~170 ms instead of ~1.3 s). Segments work that early, the playlist does not: the
manifest handler needs the WebView's message port, so the request fails with
"Port is already closed or transferred" and ExoPlayer retries with backoff — one
run lost 9 s that way, far more than the second the shortcut hoped to save.

Back to waiting for the core, with the reason written down next to the code, plus
phase logging (`adb logcat -s PlayerStartup`) so the next startup question can be
answered from numbers:

  bridge usable        460-510 ms
  playlist requested   right after
  first frame          2.39-2.62 s   (engine off: 1.69 s)

The app-side playlist repair is 4-22 ms, so the remaining time is the bridge's
own rewrite (~0.37 s for a 178-segment playlist) plus decode.
2026-11-05 11:31:08 +00:00
bac7f9c2b3 player: log how long the first frame takes (#50)
Startup was argued about with feelings; now it is measurable:
`adb logcat -s PlayerStartup` prints the milliseconds from opening a video to the
first rendered frame, tagged with whether the swarm was in play.

Measured on the emulator with a never-played public video: 1.69 s with the engine
off, 2.41 s with it on. The difference is the bridge's playlist rewrite (0.37 s
for a 178-segment playlist, since the library rescans it per segment) plus the
first segment going through the bridge — not the WebView, which now costs ~160 ms.
2026-11-05 11:24:21 +00:00
93ee026e1b player: start the video as soon as the bridge can answer (#50)
Opening a video felt slower than the metadata round trip to a server in Germany,
even though the media sits in the house. Measured on the emulator: engine ready
after 460-880 ms, first frame after 3.2 s — and the whole engine boot sat in
front of the first request.

Playback does not need the WebView core, only the Ktor server that serves the
rewritten playlist. It now waits for that socket (160-170 ms) and lets the core
finish booting in the background; any segment requested meanwhile is served by
the bridge's direct fallback, which is the pre-#50 path. First frame dropped to
2.1-2.8 s on the emulator, where software decoding dominates the rest.

The playback start threshold also drops from 2.5 s to 1 s of media: with a local
source that is one segment, and the post-rebuffer threshold still guards against
a slow link.
2026-11-05 11:13:55 +00:00
0db2ecf9e5 player: realign the bridge's shifted playlist so the swarm actually plays (#50)
The device told the real story. ExoPlayer kept dying with IllegalArgumentException
from DataSpec.subrange, and instrumenting the data specs made it obvious: it asked
for bytes 3827972-4025796 while the URI beneath it encoded 4025797-4287712. Cross
checking the whole playlist showed every segment URI carrying its successor's byte
range.

That is the same root cause as the init-segment bug: the library rewrites URIs by
name, and in a PeerTube playlist the map and every segment name the same file. The
map swallowed the first rewrite, so each subsequent replacement landed one line
early. ExoPlayer trusts #EXT-X-BYTERANGE, the bridge served whatever range its URI
encoded, and the extractor read past the declared length.

The repair now fixes the playlist rather than one line of it: the map points at the
origin file, and each segment URI is re-encoded from the BYTERANGE line above it.
Idempotent, and covered by tests built from the shifted playlist the bridge really
serves.

Verified on the emulator (real instance, public HLS video): 23 segments through the
bridge, no fallbacks, no playback errors, "1 watching" shown, buffered range
visible. The engine is on again for the TV build.
2026-11-05 10:44:58 +00:00
d769c93d47 player: engine off again so playback stays usable (#50)
The swarm path plays and then dies about ten seconds in — ExoPlayer throws
IllegalArgumentException from DataSpec.subrange inside
HlsMediaChunk.feedDataToExtractor, i.e. a chunk whose byte range does not line up
with the data it received. Until that is understood, the engine stays off and
playback takes the pre-#50 path: the playlist straight from the origin, nothing
rewritten, nothing to go wrong. Buffered bar, stall handling and the rest of the
player work is unaffected.
2026-11-05 10:18:51 +00:00
0d95cb0cfe player: decode the bridge's query-encoded map payload (#50)
The repair worked on paper but not on the TV: the bridge percent-encodes the
base64 it puts in ?segment=, so the padding arrives as %3D and a plain URL-safe
decode rejects the whole value — the repair silently returned the playlist
untouched, and ExoPlayer was back to "Cannot find sync byte". Percent-decoding
before the base64 decode fixes it, and a test now uses the padding-as-%3D shape
the device actually showed.

On the TV the video then played (visible frames, no parse error at start); a
later IllegalArgumentException from DataSpec.subrange in
HlsMediaChunk.feedDataToExtractor still interrupts playback about ten seconds
in, which needs one more debugging pass with the engine logs enabled.
2026-11-05 10:15:09 +00:00
25a4abebaa player: fix the map repair that left playback on the loading screen (#50)
The no-fork build did not play: the bridge's map URI starts with http://, so the
"already correct origin URL" shortcut fired before the bridge-form branch and the
mangled map went straight through to ExoPlayer. Segments were then rejected one
by one and the player sat on the poster with a spinner — exactly what was seen on
the TV.

Checking the bridge form first fixes it, and the repair now has unit tests built
from the playlist shape the bridge actually serves (map carrying the first
segment's range, percent-encoded map, already-correct map, no map at all,
unparseable value). The first test failed against the buggy order, which is how
this was caught without touching the TV.
2026-11-05 10:11:08 +00:00
98de77a084 player: get the swarm working without forking the library (#50)
Both blocking defects can be worked around from the app, which a second opinion
(Opus via the claude CLI) pointed out after reviewing the fork patch.

The stale core: the AAR's bundled engine matches no published release and
rejects every byte-range response. The library supports replacing it, so the app
now ships a current upstream core (4.0.0, 110 KB, Apache-2.0, unmodified) at
custom-static/ and passes customEngineImplementationPath.

The mangled init segment: the playlist passes through the app on its way into
ExoPlayer, so HlsMediaSource now uses MapUriRepairingParserFactory, which decodes
the #EXT-X-MAP URI back to the origin file — base64 ?segment= form,
percent-encoded form, or already correct — and leaves it there. The init data is
a few hundred bytes and needs no swarm. Idempotent on purpose.

The fork wiring is gone again; the patch stays in tools/p2p-core-patch as the
upstream proposal. Verified: builds and unit tests pass. On-device confirmation
is pending — the TV was in use by a child when the build went in.
2026-11-04 23:04:56 +00:00
7f9a834001 docs: upstream the simpler manifest rewrite a reviewer recommended
A second opinion (Opus, via the claude CLI) on the fork patch replaced the
per-segment search-and-replace with a single pass over the playlist: tag URIs
(#EXT-X-MAP, #EXT-X-KEY) are made absolute, and every URI line — a media
segment — is by position what the parser produced. Position, not name, is also
how the hls.js integration does it, so this is closer to the web player and
immune to the map/segment name collision by construction, including multi-map,
CRLF and I-frame playlists. The URL-encoding fix stays a separate, one-line
change as the reviewer suggested.

The fork builds with it and the app assembles against it; the on-device
verification is still pending (the last attempt landed on a different screen).
2026-11-04 22:51:41 +00:00
fc1929c0a9 docs: the fork patch in its reviewable form
Comments merged and the dead intermediate variable dropped, so the diff reads
as three deliberate changes rather than a trail of iterations. Rebuilt against
the fork and re-verified: the app assembles, and this is the exact patch an
upstream PR would carry.
2026-11-04 22:38:26 +00:00
7e7fa13929 player: show how many are watching, and build P2P only against the fork (#50)
PeerTube's API has no concurrent-viewer figure for VOD, but the swarm does:
every viewer is a peer in the tracker. The controls now show "1 watching" /
"3 watching" next to the timing — peers plus this device — so the count is
honest about meaning "only you" rather than reading as an empty state.

The engine needs two library fixes that are not upstream: a current core (the
published one rejects every byte-range segment) and an init segment that keeps
its own range instead of inheriting the first segment's. Both live in
tools/p2p-core-patch/fork-init-segment.patch. So P2P is now tied to the build:
-Pp2pForkPath=… substitutes a patched checkout and sets BuildConfig.P2P_ENABLED;
without it the app plays from the origin exactly as before.

This replaces the earlier build-time patching of the bundled core: with the
init-segment bug in Kotlin, patching the JavaScript alone could never make the
swarm work. Verified on the TV with the fork: segments served through the
engine, no fallbacks, no playback errors.
2026-11-04 22:30:10 +00:00
870f54db75 player: make the buffered range actually visible, and park the fork patch
The buffered segment was 0x77 white on a 0x55 track — two greys that a TV
viewer cannot tell apart, which read as "the buffered bar is gone again". It is
now bright white (0xE6) over a dim track (0x3D), still drawn under the played
part so the red always wins.

tools/p2p-core-patch/fork-init-segment.patch keeps the work-in-progress fork
fix for the init segment (#50): rewriting #EXT-X-MAP first, line-based segment
rewriting so the map's identical file name cannot be clobbered, and not
URL-encoding a plain playlist URL. Verified on the TV (no more "Cannot find sync
byte"), but segments still reach the player only through the HTTP fallback, so
the engine needs one more round of debugging on the device.
2026-11-04 22:14:59 +00:00
5d6783b32a docs: the patched core works; the init segment is the next blocker (#50)
With the Content-Range patch in place the engine really does deliver segments
("Segment bytes received", 3 s for the first one) — the byte-range rejection is
settled.

Playback still stops immediately, now in the player: ParserException "Cannot
find sync byte" in maybeLoadInitData. Reading the rewritten playlist from the
engine's own server shows the init segment carrying the first media segment's
range, because the library replaces the first occurrence of the segment file
name — and in PeerTube playlists #EXT-X-MAP names that same file. A Kotlin-side
bug, so no asset patch can reach it: it needs a fork/vendored module, or a
distinct MAP URI on the mirrored playlists.

Engine back to off so the TV keeps playing; findings recorded for whoever picks
it up.
2026-11-04 21:34:47 +00:00
4a17fb25ec player: patch the P2P core so byte-range segments are accepted (#50)
The engine failed every segment of every PeerTube playlist. Running the
library's own glue and core against a real playlist in a desktop browser
reproduced it exactly, and the core's error class named the reason:
http-bytes-mismatch.

Its HTTP loader compares the Content-Range total against request.totalBytes,
but that field is only ever set from a 200 response. PeerTube's segments are
byte ranges answered with 206 and a total, so the comparison can never pass —
the correct bytes are downloaded, rejected, retried and finally reported as
failed, and playback limps along on the HTTP fallback.

The fix is one condition: compare the total only when the loader knows one.
Verified in the harness against three arbitrary ranges of a real fragmented
file, byte-exact.

Rather than vendoring 160 KB of minified JavaScript, tools/p2p-core-patch
carries the anchor, the replacement and the sha256 of both the original and the
patched bundle; patchP2pCore extracts the core from the dependency AAR at build
time, verifies the hash, substitutes and serves the result as a custom engine
implementation. A dependency bump that changes the bundle fails the build
instead of silently losing the fix.

The upstream write-up is in tools/p2p-core-patch/UPSTREAM.md; the swarm itself
is still to be confirmed on the TV.
2026-11-04 21:30:51 +00:00
b5a2916d14 docs: map the P2P components, retract a wrong root cause
The architecture note answers "where does each piece live" across the server,
the web client, the official Android app and this one, because the gap is only
visible when the four are side by side: the server emits a swarm-friendly
layout and runs a tracker, the web client has a maintained range-aware engine,
the official Android app never tried, and the Android wrapper we depend on is
where every segment currently fails.

The byte-range claim in the #50 note was wrong: the bundled core does send Range
headers, check 206 and handle byteRange on the segment object, and the library's
runtimeId matches on both sides. Recording what is actually known, and that the
next step is the engine's own debug log rather than a redesign.
2026-11-04 07:34:18 +00:00
77dc74fea6 player: keep the swarm off until it can address byte-range segments
Enabling the engine made playback dramatically slower: every HLS segment was
handed to a core that identifies segments by URL, failed on PeerTube's
byte-range URLs, and only then fell through to HTTP. That costs seconds per
four-second segment, so anything not on a fast local origin never started, and
even local playback stuttered. The 4 s engine boot also delayed every open.

The code stays behind P2PPlayback.ENABLED (false) so the finding is not lost
and the switch is one line once the core can identify range-addressed
segments. The post-rebuffer threshold also drops from 8 s to 5 s: 8 s only
helps a link whose bandwidth hovers at the bitrate, and it makes every stray
hitch cost eight seconds.
2026-11-04 06:14:09 +00:00
6a29b700b8 docs: byte-range HLS cannot be swarm-served yet
Verified on the TV: the engine joins, but every segment of a PeerTube
object-storage playlist fails in the core and falls back to HTTP. The library
encodes a byte-range segment as url|start-end for its direct-fetch path and
hands the same string to a core that identifies segments by URL alone, so
nothing ever matches — 19 errors, no peer.

Recording the observation and the two fixes that belong on the media host
(per-segment files, or unique URLs mapped to Range requests) so the next
person does not re-derive them from logcat.
2026-11-04 05:51:14 +00:00