Introducing a new way to review your PRs.

Read the announcement

4gray / iptvnator

:tv: Cross-platform IPTV player application with multiple features, such as support of m3u and m3u8 playlists, favorites, TV guide, TV archive/catchup and more.

View on GitHub

26 documents · Updated Nov 23, 2026

docs / tv-shell-runtime

Android TV shell runtime

The Android TV shell packages IPTVnator as a full-screen TV app with no separately hosted server. It starts an embedded local web server, serves the bundled IPTVnator web app through a WebView, adapts provider traffic to the web app's API contract, and maps remote-control actions to native Android or page actions. The result is one local origin that keeps the web app's saved data stable while the Android layer supplies the TV lifecycle and platform services. tv-shell/README.md• L3-8

Runtime boundary

The runtime has three linked parts: the Android activity owns the screen and lifecycle, the loopback server joins the bundled web app to the embedded backend, and the web layer provides the IPTVnator experience. The server listens only on 127.0.0.1, so the WebView and the backend share a local origin without exposing the shell as a LAN service. tv-shell/…/TvShellServer.java• L25-33, tv-shell/README.md• L108-120

The application starts the server when the Android process starts. It keeps the saved port as the web app's origin because WebView storage is tied to that origin. If the port is busy, the shell uses a temporary port for the current run and returns to the saved port when it becomes free. tv-shell/…/ShellApp.java• L9-12, tv-shell/…/ShellApp.java• L26-31

The main activity loads the local page in a full-screen WebView. It shows a splash screen until the page reports readiness, then shows a focused error panel when the server, WebView, bridge, or page cannot start. A renderer restart can recreate the activity while the application keeps the local server alive. The activity builds the WebView in code so a missing or updating system WebView can produce a useful error instead of a launch crash. tv-shell/…/MainActivity.java• L49-67, tv-shell/…/MainActivity.java• L152-167, tv-shell/…/MainActivity.java• L341-377

The runtime flow is:

flowchart LR
    A[Android process] --> B[Local loopback server]
    B --> C[Bundled IPTVnator web app]
    B --> D[Embedded web backend]
    C --> E[Provider playlists and portals]
    C <--> F[Android WebView bridge]
    F --> G[Remote control and Android services]

References: tv-shell/…/ShellApp.java• L9-31 tv-shell/…/TvShellServer.java• L25-33 tv-shell/…/MainActivity.java• L126-177

Native application lifecycle

The native lifecycle keeps the TV screen usable across launch, pause, resume, configuration changes, and low-memory events. The activity pauses page media when it leaves the foreground, restores the last route when Android recreates it, and keeps the screen awake only during startup or playback. Returning to the foreground also lets the page close transient TV UI such as trailers and stop late playback retries. tv-shell/…/MainActivity.java• L630-687, tv-shell/…/tv.js• L1023-1030, tv-shell/README.md• L241-247

The shell treats WebView failure as a recoverable runtime event. It retries a failed local load after restarting the server, reports a page that never becomes ready, and recreates the WebView after a renderer death. Repeated renderer deaths in a short period stop the reload loop and present diagnostics instead. tv-shell/…/MainActivity.java• L56-67, tv-shell/…/MainActivity.java• L209-269

The activity also provides TV-safe handling for external links, document selection, fullscreen video, and installed external players. Playlist import and backup restore use the Android document picker without broad storage access. Backup export is not available in this runtime. A stream that the WebView cannot play can be offered to an Android video player such as VLC. tv-shell/…/MainActivity.java• L187-205, tv-shell/…/MainActivity.java• L272-276, tv-shell/…/MainActivity.java• L568-648, tv-shell/README.md• L24-31

References: tv-shell/…/MainActivity.java• L246-269 tv-shell/…/MainActivity.java• L630-708 tv-shell/…/ExternalPlayer.java• L71-94 tv-shell/…/tv-remote.mjs• L897-917

Playlist and portal adaptation

The local backend presents the same web-backend contract that IPTVnator expects. It lets the page register a provider URL once, then uses a short target ID for later playlist and portal requests. This keeps provider URLs out of repeated browser requests while preserving the web app's request shapes. tv-shell/…/WebBackend.java• L12-29, tv-shell/…/WebBackend.java• L123-157, tv-shell/README.md• L85-91

Playlist adaptation

Playlist adaptation turns a provider's M3U response into the playlist record used by the web app. The shell parses the stream as it reads it, adds channel identity and playback metadata, and returns the result as a JSON record. The parser follows the IPTVnator playlist format so imported lists behave like lists loaded through the web backend. tv-shell/…/WebBackend.java• L160-196, tv-shell/…/PlaylistBuilder.java• L49-75, tv-shell/…/M3uParser.java• L9-17

The backend keeps the playlist path bounded for TV devices. Provider responses have a memory limit, and the generated record is streamed to the local HTTP response instead of being rebuilt as a second large object. This allows large lists to fail with a clear provider error rather than taking down the app. tv-shell/…/HttpFetcher.java• L45-61, tv-shell/…/TvShellServer.java• L184-207, tv-shell/README.md• L257-268

References: tv-shell/…/WebBackend.java• L160-196 tv-shell/…/PlaylistBuilder.java• L49-75 tv-shell/…/M3uParser.java• L9-17 tv-shell/…/tv-longlist.mjs• L24-67

Portal adaptation

Portal adaptation maps the two supported portal styles into the calls expected by IPTVnator. Xtream requests normalize the server URL and return provider data with the requested action. Stalker requests add the identity, cookie, and authorization form expected by a MAG-style portal before forwarding the action. tv-shell/…/WebBackend.java• L198-265, tv-shell/…/StalkerIdentity.java• L89-102

Provider errors keep the web app's normal error model. Xtream and Stalker provider failures use an HTTP success response with an error body, while playlist and shell validation errors use an HTTP error status. The page can therefore apply the same user-facing handling in the TV shell and in the regular web backend. tv-shell/…/WebBackend.java• L218-235, tv-shell/…/WebBackend.java• L260-264

References: tv-shell/…/WebBackend.java• L198-265 tv-shell/…/PortalUrls.java• L48-69 tv-shell/…/StalkerIdentity.java• L89-102 tv-shell/…/tv-remote.mjs• L109-156

The adaptation path is:

sequenceDiagram
    participant P as IPTVnator page
    participant S as Local server
    participant B as Web backend
    participant V as Provider
    P->>S: Register provider URL
    S->>B: Store normalized target
    B-->>P: Return target ID
    P->>S: Request playlist or portal action
    S->>B: Resolve target and adapt request
    B->>V: Fetch provider data
    V-->>B: Playlist or portal response
    B-->>P: IPTVnator-compatible result

References: tv-shell/…/WebBackend.java• L87-120 tv-shell/…/PlaylistBuilder.java• L59-75 tv-shell/…/PortalUrls.java• L48-69 tv-shell/…/StalkerIdentity.java• L89-102

Web app packaging

The APK carries a built IPTVnator PWA as local assets. The shell serves the page and its static resources from that bundle, applies a TV viewport and the TV script, points the page at the local backend, and disables service-worker files so an older cache cannot hide a new APK bundle. tv-shell/…/ShellSite.java• L10-22

The TV script is loaded before the web bundle from the same origin. It does not change IPTVnator source files. It adds the TV layer, reports readiness after the app renders, and supports a temporary player-loading mode when all player engines must load before Angular starts. tv-shell/README.md• L224-237, tv-shell/…/tv-remote.mjs• L866-895

The TV viewport uses a configurable layout width and the device's CSS screen width. This lets the same web app use a readable, normal, or dense layout while keeping the page scale fixed for the TV display. Unknown application routes fall back to the app entry page so the single-page app can restore its route. tv-shell/…/ShellSite.java• L132-177, tv-shell/…/Prefs.java• L24-31, tv-shell/README.md• L248-251

The packaging flow builds the PWA, copies it into Android assets, removes service-worker files, and then builds the APK. The Android build keeps web assets uncompressed so the local server can serve them directly from the package. tv-shell/…/bundle-pwa.sh• L1-17, .github/…/build-tv-shell-apk.yml• L94-112, tv-shell/…/build.gradle• L65-70

References: tv-shell/…/ShellSite.java• L106-141 tv-shell/…/bundle-pwa.sh• L7-17 tv-shell/…/build.gradle• L5-17 tv-shell/…/tv-remote.mjs• L875-917

Remote-control bridge

The remote-control bridge connects page behavior to Android behavior without giving arbitrary page code native access. The WebView accepts messages only from the expected local origin and only from the trusted main frame. The native receiver accepts a small JSON command list and ignores malformed or oversized messages. tv-shell/…/MainActivity.java• L379-392, tv-shell/…/TvShellBridge.java• L10-29, tv-shell/README.md• L116-128

The bridge carries a small set of platform actions:

DirectionPurpose
Page to AndroidReady state, screen wake state, settings, keyboard, toasts, app exit, playback diagnostics, and external-player requests
Android to pageBack, menu, media-key actions, and foreground state

The TV script gives the page spatial focus, overlay handling, fullscreen behavior, media control, and stream handoff. Its focus model moves through virtual channel lists, player controls, form fields, native checkboxes, radio groups, and visible trailer frames without trapping the remote in structural containers. Android handles keys that the WebView does not expose reliably, then forwards the matching page action through window.__tvShell. tv-shell/…/MainActivity.java• L459-587, tv-shell/…/tv.js• L7-24, tv-shell/…/tv.js• L491-627, tv-shell/…/tv-longlist.mjs• L36-103, tv-shell/…/tv-remote.mjs• L83-105

Back follows the TV navigation order: close an overlay, leave fullscreen, leave the focused player, return through page history, then ask the native app to exit after a second press. Menu opens the focused item's context action, while media keys control the active media element. OK activates controls once, opens the keyboard only after a text field receives OK, and preserves native caret or range behavior where the page needs it. tv-shell/…/tv.js• L824-865, tv-shell/…/tv.js• L945-1021, tv-shell/…/tv.js• L1032-1105, tv-shell/…/tv-remote.mjs• L1098-1173

Playback handoff uses the source stream rather than a fetched segment. The TV layer tracks native media sources and the first request in a MediaSource session, ignores provider metadata and media segments, and keeps the current source through player recovery. It offers an external player for unsupported codecs or containers, but not for a normal network failure. tv-shell/…/tv.js• L1108-1245, tv-shell/…/tv.js• L1252-1401, tv-shell/…/tv-remote.mjs• L278-425, tv-shell/…/tv-remote.mjs• L463-586

References: tv-shell/…/MainActivity.java• L459-591 tv-shell/…/TvShellBridge.java• L18-65 tv-shell/…/tv.js• L785-907 tv-shell/…/tv.js• L1108-1473 tv-shell/…/tv-remote.mjs• L426-602

Platform packaging

The Android package targets Fire OS and Android TV devices from Android 7.1 onward. It supports both the normal launcher and the Leanback launcher, does not require a touch screen, and declares network access for provider traffic and wake access for playback. tv-shell/…/build.gradle• L5-16, tv-shell/…/AndroidManifest.xml• L2-16

The package permits cleartext traffic because the shell uses an HTTP loopback origin and many IPTV providers use HTTP. It disables Android backup because WebView storage can contain portal credentials. Release builds are non-debuggable and use a configured release key when available. tv-shell/…/AndroidManifest.xml• L25-40, tv-shell/…/build.gradle• L19-51, tv-shell/README.md• L121-133

The build workflow validates the shell backend and remote-control behavior, builds the PWA, bundles it, and produces an APK artifact. A manual release can publish the APK as a GitHub release. tv-shell/README.md• L135-158, .github/…/build-tv-shell-apk.yml• L1-10, .github/…/build-tv-shell-apk.yml• L174-217

References: tv-shell/…/AndroidManifest.xml• L8-56 tv-shell/…/build.gradle• L46-80 .github/…/build-tv-shell-apk.yml• L163-217

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the saved loopback port and the WebView origin aligned. A port change can make saved playlists and portals appear to disappear.
  • Keep /api route shapes and error bodies aligned with the web backend. The PWA uses these shapes as its provider contract.
  • Regenerate playlist fixtures and update the Java parser when the bundled JavaScript playlist parser changes.
  • Keep tv.js, the native bridge command names, and the Android key mapping in sync. A change on one side can silently disable remote actions.
  • Keep the playback URL tracker aligned with player engine behavior. A change can hand a manifest segment or credential-bearing request to an external player.
  • Keep foreground handling aligned with media and trailer cleanup. A page change can leave playback or a cross-origin frame active after navigation.
  • Rebuild and bundle the PWA before packaging the APK. The APK serves the asset bundle rather than the source web app.
  • Preserve the package's cleartext and backup policy when changing the manifest. Both affect provider access and credential safety.

Important failure modes

TriggerConsequenceGuard
Saved server port is occupiedWebView uses a temporary origin and saved web data is not visible for that runRetry the saved port, use a fallback only for the run, and return to the saved port when free
WebView is missing or too oldThe page cannot load or report readinessShow the native error panel with WebView diagnostics
Local server load failsThe WebView sees a failed main-frame requestRestart the server and retry once
Web renderer dies repeatedlyReloading can loop on a low-memory deviceRecreate once, then stop and show a renderer failure message
Provider response exceeds device limitsPlaylist or portal data cannot be safely held in memoryCap fetched bodies and return a provider error
EPG XML is requestedThe TV shell cannot provide XMLTV dataReturn a clear not-available response
Bridge message is malformed, oversized, or from another originNative actions could be ignored or exposed to untrusted contentCheck origin, main-frame status, message type, size, and JSON shape
Remote repeats arrive before the prior focus move is drawnFocus can skip visible list items or controlsDrop queued repeats and allow one held-key move per drawn frame
Player reports a network failureAn external-player prompt would offer the same failed streamOffer handoff only for unsupported format or decode failures

Key files

FileWhy to read it
tv-shell/…/MainActivity.javaMain WebView lifecycle, TV key handling, load recovery, and native platform actions
tv-shell/…/ShellApp.javaServer startup and stable-versus-fallback port behavior
tv-shell/…/TvShellServer.javaLocal HTTP boundary between the WebView, bundled site, and backend
tv-shell/…/WebBackend.javaAPI contract for playlists, Xtream, Stalker, and shell configuration
tv-shell/…/ShellSite.javaPWA asset serving and TV-specific page adaptation
tv-shell/…/PlaylistBuilder.javaShape of playlist records returned to the PWA
tv-shell/…/PortalUrls.javaURL rules for Xtream and Stalker provider requests
tv-shell/…/TvShellBridge.javaNative command boundary for page-to-Android actions
tv-shell/…/tv.jsTV focus, remote navigation, media controls, playback handoff, and page-to-native calls
tv-shell/…/AndroidManifest.xmlTV capability, network, backup, and launcher package rules
tv-shell/…/tv-remote.mjsEnd-to-end remote, bridge, playback, startup, and keyboard behavior
tv-shell/…/tv-longlist.mjsVirtual-list navigation and player-control reachability
.github/…/build-tv-shell-apk.ymlEnd-to-end validation, PWA bundling, and APK packaging flow

See also: Television client, Television browsing and playback