Skip to content
Go back

Going native: an Android client over the same APIs

Updated:

I wanted a native player for a phone connected to a larger screen, with downloads managed by Android and direct control over the video surface. The web app already had the backend, so the Android app could use the same JSON APIs and signed media URLs.

That keeps catalog and render logic in one place. It also exposes assumptions that a browser normally handles for me, especially cookies and login redirects.

This is part of Stream of Worship, a series. Previous: Offline worship playback. Next: Ten build phases.

Start with the same origin

The app uses OkHttp with a persistent cookie store. It tries encrypted preferences first, but falls back to ordinary app-private preferences if encrypted initialization fails twice. Cookies can be restored after process death. Startup auth resolution needs to avoid treating an incidental unauthorized response as the final answer before restore completes.

Cookies remain scoped to their host. The emulator’s 10.0.2.2, a computer’s LAN address, and the deployed app domain aren’t interchangeable. If login works but the next request is unauthorized, checking the configured origin is a useful first step.

The Android README documents that setup. I don’t have support counts that would justify calling host mismatch the most common user problem.

The video screen owns its player

The worship screen uses an in-process ExoPlayer built by VideoExoPlayerFactory. It attaches directly to a video surface, handles unplugged-headphone events, enables decoder fallback, and uses network wake mode.

There is also a MediaSessionService in the tree. Its comment explicitly says the current video screen doesn’t use it; it was retained for possible background audio. Its presence doesn’t mean the worship screen provides background playback or lock-screen controls through that service.

Lifecycle changes need special care. A surviving view model can retain a controller after the old activity’s player has been released. The playback fixes rebind the active controller. That is a concrete lifecycle issue, rather than proof that playback survives every screen-off or process-death case.

Chapters and lyrics

The client reads the render worker’s chapter sidecar and normalizes it before use. Playback position selects the current song and lyric line. Tapping a line can seek, while chapter changes drive the larger scroll movement.

The MP4 already contains lyrics, so this panel is a controller aid. Keeping the chapter timeline aligned with the rendered mix matters more than duplicating the renderer’s layout on the phone.

Signed URLs can expire. The client checks expiry using the device clock and offers a refresh path for stale URLs. A local check is only a convenience when the clock is correct; the server still decides whether a URL is valid.

Let Android download the files

The download scheduler calls DownloadManager directly. It allows metered connections, disallows roaming, and requests a completion notification. This path isn’t a WorkManager download worker.

Metadata tracks each artifact separately. Video may be ready while the chapters file has failed. The coordinator saves queued metadata before enqueueing, and the completion receiver can recover the render-job ID and artifact kind from the title if completion arrives before the download ID is saved.

The offline repository writes metadata through a sibling temporary file and replacement. Corrupt metadata loads as empty. That protects launch from a bad file, though losing the index isn’t the same as recovering every downloaded artifact.

The coordinator tests and repository tests cover those boundaries. Device networking, HDMI output, and decoder behavior still need device testing. CI produces a debug APK; release signing remains a separate task.


Share this post on:

Previous Post
Offline worship playback: downloading the player as well as the video
Next Post
Ten build phases: what Stream of Worship taught me