# IPTVnator (Android and Fire TV) **IPTVnator for Android and Fire TV** is an experimental platform build. It runs the **IPTVnator browser app** on Android phones, tablets, TV boxes and Fire TV sticks. The Java backend is embedded in the APK for standalone use. The Android build shares the IPTVnator name and web interface with desktop and PWA builds. _[Version française](README.fr.md)._ ``` APK ├── full-screen WebView ──► http://127.0.0.1:43330/ (loopback server, NanoHTTPD) │ ├── / IPTVnator PWA (assets/www, the Angular bundle) │ ├── /tvshell/tv.js the remote-control layer injected into index.html │ └── /api/* embedded backend: M3U parsing, Xtream and Stalker proxies └── Back / Menu / media keys → tv.js ; streams the WebView cannot play → VLC (intent) ``` > Experimental shell maintained in this repository (`tv-shell/`): it embeds the > IPTVnator PWA built from these sources. If you redistribute a modified build > outside the project, apply [`TRADEMARK.md`](../TRADEMARK.md) (distinct name > and icon). ## Hosted library connection Native Settings offers **Local library** and **Connect to hosted library**. Enter an HTTP or HTTPS address for a running IPTVnator hosted server; the shell checks its instance endpoint before switching. Leaving Settings, starting a pairing or scan, or selecting the local library cancels the check. Use the hosted page's sign-in for its access code. On phones and tablets, **Settings → Connectivity** also connects directly to a server from the bundled app. Local data and the saved hosted address remain available when switching modes. HTTP is intended for trusted networks; HTTPS uses normal certificate validation. If the hosted server cannot load, the app opens the local library and keeps the preferred server and its paired device credential. The next launch tries the preferred server again. You can also reconnect from Connectivity. NAS and Cloudflare Access libraries load the player from the APK. On a slow device, these screens get the same startup time as the standalone library. Disconnect selects the local library in Touch and TV layouts. Selecting a separate source-sync server on a hosted page keeps that choice after a reload. Remove pairing also erases the device's stored credential. Server-side revocation is available under Paired devices. Reconnect accepts a saved pairing only after the server reports the matching instance ID. A different instance at the same address requires its own pairing. When you switch back to a desktop server that revoked this device, Android requests a new pairing. The current library stays open until approval. A hosted page requires an up-to-date Android System WebView. External redirects are blocked; choose another server explicitly in Settings. Other user-selected HTTP(S) links open in the system browser. External playback accepts HTTP(S) provider URLs; hosted-server URLs stay inside the app. ### Register with a QR code In Android, choose **Settings → Connectivity** and tap **Scan QR code** under **Library connection**. Scan the **Pair a device** QR from the server's **Paired devices** section, or tap **Choose image** in the scanner to read it from a saved screenshot or photo. A phone camera also opens the QR's landing page, where **Open IPTVnator** opens the same pairing flow using `iptvnator://pair?server=&invite=`. Android shows the exact server address and asks for confirmation before contacting it. Compare the six-digit code on Android with the pending request on the originating device and approve there. Keep Android in the foreground while waiting; cancelling or leaving Settings preserves the previous library selection. After approval, Android remembers that hosted server and stores its own device credential encrypted with Android Keystore, bound to both origin and verified instance ID. The hosted PWA obtains it only through the origin-scoped, main-frame `HostedPairing` bridge after verifying that instance. The bridge accepts `{action: 'credential', instanceId}` and replies with `{token}` (null for a mismatch); `{action: 'forget', instanceId}` erases it and acknowledges `{forgotten: true}`. Resetting app data also removes native paired credentials. The flow rejects redirects and never puts credentials in a URL or diagnostics. Starting another pairing cancels pending Cloudflare sign-in. Approving ordinary pairing at the same HTTPS address replaces its saved Cloudflare session. Removing a pairing also invalidates active sessions, including a refresh already in progress. HTTP pairing is intended only for a trusted local network. This does not bypass Cloudflare Access; a separately protected instance must be reachable by the app. ### Cloudflare Access On the PC, start the server in **Cloudflare Tunnel** mode and open **Pair a device** after the public route is verified. Scan that QR inside Android IPTVnator and choose **Sign in with Cloudflare Access**. Sign-in opens an Android Auth Tab, or a Custom Tab on browsers that use the fallback. IPTVnator verifies the library's instance ID before switching libraries. Enable [Managed OAuth](https://developers.cloudflare.com/cloudflare-one/access-controls/applications/http-apps/managed-oauth/) and dynamic client registration on the Access application. Allow exactly `org.tvshell.iptvnator://oauth/callback` as the Android redirect URI. The app keeps tokens in Android Keystore-backed storage and runs the bundled UI with a native bridge for the selected server's API. A manually entered Access URL can still open the web player in the system browser. Each Access library uses its own HTTP `.localhost` origin for the bundled UI. The WebView can play plain HTTP streams directly. The native bridge sends Access and device credentials only to the selected server's HTTPS API. Earlier preview APKs used an HTTPS `.iptvnator.invalid` origin. Pairing and server-side library data carry over. WebView preferences, cached catalogs and unsynced favorites, history or progress stay in the old origin's storage. Before updating a preview, let any enabled sync finish. The new profile reads the shared library again. You can import an existing playlist backup and reapply device-local web preferences. The Android shell supports backup import only. Run the origin, redirect and QR checks with `cd tv-shell/android` then `./gradlew :app:hostedConnectionTests`. Verify native sign-in, cancel/retry, restart, token expiry and playback on a phone over mobile data using a controlled Access application. For a debug APK already paired to a synthetic loopback server, run `ANDROID_HOME=/path/to/sdk node tv-shell/tests/android-hosted-reconnect.mjs emulator-5556 http://127.0.0.1:43340` with that server's port reversed through ADB. The paired-only fixture needs an M3U source named `Synthetic Android library` containing a playable video channel named `Synthetic playable clip`. The regression re-enters the server address after Disconnect, then uses the saved Connect shortcut after a simulated HTTP 503. Both paths must load the protected inventory with the existing pairing. It also verifies channel selection and decoded playback after visiting Settings. On a disposable emulator, run [the library connection tests](tests/android-library-connections.mjs) in `hosted` mode to pair two Electron servers and switch between them, or in `nas` mode to test open and token-protected Docker servers. The script lists the fixture setup and checks which library reopens after a cold start. ## What it does The Android WebView and the PWA's vertical page scrollers stop at their scroll edges. The native bridge activates the PWA rule, so browser remote emulation keeps browser scrolling behavior. Local playlist import and backup restore use Android's document picker, without broad storage permissions. Cancellation leaves the file input unchanged; devices without a document picker show an explanatory message. The shared parsers validate the selected document. Backup export is unavailable in this runtime until a native document-save flow exists. Settings offers import only; a programmatic export cannot report success. The temporary player-loading rollback is `localStorage.setItem('iptvnator.eagerPlayerLoading', '1')`, followed by a reload: all engines load before Angular starts. Remove the key to restore deferred loading. Remove this rollback by release 0.27 (within two releases of 0.25). Returning from a deep catalog position synchronizes the TV grid before restoring card focus. Shared playback diagnostics publish `iptvnator:playback-issue` with only a code; the shell uses unsupported-codec/container and decode errors to offer an external player even when the engine does not raise a native media error. Network errors remain excluded and duplicate diagnostics share the existing per-load prompt limit. Parser fixtures use synthetic catalog metadata and reserved provider endpoints before the reference parser generates expected output. Run `node --test tv-shell/tests/*.test.mjs` for fixture privacy and reference-backend redirect checks. The APK workflow runs these checks alongside the Java and remote-control suites. Cross-origin redirects drop authorization, cookie, proxy authorization, serial and Host headers. The reference server also accepts a leading JSON BOM and forwards Xtream's trimmed User-Agent as a header, excluding it from provider query parameters. Malformed redirects and interrupted response bodies return provider errors. An HTTP response, including a redirect, rules out an HTTP retry during protocol discovery. The embedded backend checks compressed response lengths before accepting playlist data. The Node reference server allows the local mock provider by default. For other providers, set `TVSHELL_PROVIDER_ORIGINS` to a comma-separated list of HTTP(S) origins such as `https://provider.example`. Registration and every redirect hop must use a configured origin. The embedded Android backend has its own provider policy and encodes spaces in registered playlist URLs without re-encoding existing escapes. The Node server serves static files and the SPA entry point from the configured `--www` directory, with symbolic links confined to that directory. - **Remote-control navigation**: the D-pad moves the focus between the app's focusable elements (a JavaScript port of Android's FocusFinder), OK activates, Back closes dialogs and menus then walks the history, Menu opens the focused item's context menu, play/pause/rewind/fast-forward drive the video. Virtual lists of thousands of channels work: the next row, already rendered past the fold, is the next stop, and a held arrow moves once per drawn frame. Material checkboxes and radios keep native input focus, with the focus ring painted on their visible component even when the input itself is transparent. Up/Down can leave a native radio group; Left/Right retain native radio selection. In the source switcher, Up/Down highlight sources; horizontal arrows move the search caret and leave it at the boundary. Menu opens the highlighted source's actions through the app's keyboard handler, with a mouse context-menu fallback. Visible trailer iframes can receive remote focus and handle their own keys; hidden background embeds remain excluded. Leaving the Android activity closes the trailer dialog and unloads its player. HTTP protocol discovery requires positive refusal evidence from every connection-error cause; ambiguous failures never authorize a plaintext probe. The transparent playback-position input stays focusable, with its ring on the visible track. Bridge diagnostics log method names without arguments or exception text, so stream URLs and credentials stay out of browser-emulation logs. Structural list-item wrappers are not remote actions: dashboard cards focus their links, and a programmatic landing on a wrapper enters its actionable child. - **M3U playlists by URL, Xtream Codes portals, Stalker portals** through the embedded backend: the same route contract as `apps/web-backend`, with the M3U parser ported line by line and checked against 43 fixtures generated by the real JavaScript parser (`tools/gen-parser-fixtures.mjs`, verified in CI). Provider JSON accepts a leading UTF-8 BOM; response-body timeouts, decoding failures and truncated plain responses with a declared length are transport errors even after HTTP 200 headers arrive. - **Playback** with the PWA's own players (HLS `.m3u8`, MP4, DASH ClearKey) in the WebView. Streams a browser cannot play (raw `.ts`, AC3 audio...) trigger a **"This stream cannot be played here"** prompt offering to open them in another player (VLC, Kodi, MX Player...). When Media3 is available, you can try it first. If it fails too, the shell offers the external player after Back, provided the external-player prompt is enabled. Enabling Media3 in settings preserves a web error for the same playback attempt. The app's "Copy stream URL" button also offers an external player on a TV. - On phones and tablets, open **Settings → Connectivity**, enter the server address, and tap **Connect**. The app connects to a stock Docker server and prompts for its access token when required. To switch from one desktop server to another, enter the new address here, confirm it, and follow the pairing prompt if this is your first connection to that server. For a new Cloudflare Access connection, use **Scan QR code** to open an invitation from the host. The scanner also reads TV approval codes on a phone with device approval permission. Under **Advanced**, you can open the hosted web player, enter an optional HTTPS address for pairing approval, or remove an existing pairing. **Disconnect** returns to the local library. Choose **Playback → External player settings** for the experimental built-in player and Android external-player preferences, or **Android device → Open settings** for diagnostics, data reset and layout options on wider screens. The Android launcher also offers a **Device settings** shortcut when you hold the app icon, including for older hosted libraries. On a TV remote, hold Menu or Back to open the TV settings. On a TV using the Touch layout, the Android settings shortcuts open the full TV settings screen. - During playback on a phone or tablet, use **Open in another player** from the player controls to hand the current stream to an installed Android player. - Data (playlists, favourites, positions) is stored by the PWA in the WebView (IndexedDB / localStorage) and survives restarts and updates. The embedded backend has no server storage: it answers the PWA's `/api/v1/instance` probe with 404, the answer of a backend without it. Inherited PWA limits: no EPG/XMLTV, no downloads, no embedded MPV (desktop-only features in IPTVnator). ## Trying the built-in player On a phone or tablet, open the gear and choose **Playback → External player settings**. On a TV remote, hold Menu or Back. Turn on **Enable built-in player (experimental)**. Open a channel or start a video, then select **Try built-in player** in the video area. It is also available when the web engine reports an error. The built-in player starts at the current app volume. If muted, the web player restores the previous audible level when you unmute after switching back. Back returns to the same page. Home ends native playback and keeps the position when you return to the app. When a series episode finishes, IPTVnator applies the series autoplay setting and starts the next eligible episode in the web player. Choose **Return to web player** to compare the two engines on the same stream. The pilot plays HLS, including HLS variants of Smooth Streaming manifest paths, and direct HTTP(S) video such as MP4, MPEG-TS and MKV. Audio and video codec support varies by device. The built-in player uses FFmpeg to decode AC-3 when the device cannot handle it. DASH, DRM, Smooth Streaming and temporary Stalker links stay in the web player. When parental controls are enabled, playback stays in the web player so it can enforce the lock. The native fullscreen screen supports play/pause, VOD seeking, audio tracks and subtitles. Its mute button restores the last audible app volume when unmuting. The Show subtitles setting picks the initial subtitle track and the native controls can change it. The player keeps the play state and selected tracks through rotation. The top control bar provides Back, Audio, Subtitles, Quality, Picture and Mute. The bar scrolls horizontally on narrow screens and can be navigated with a remote. Up enters the top bar; Down returns to play/pause. Track dialogs keep the controls visible until dismissed. Back closes a dialog before leaving playback; the on-screen back arrow also returns the playback position to the web app. Quality lists the source's supported video variants and an automatic option; a single-variant file shows Original. Picture offers Fit, Zoom (crop), Stretch, 16:9 and 4:3, and preserves the selection through rotation and quality changes. The back arrow stays available when playback fails. The player saves the VOD position when you leave, including after seeking. Open the web player to use the channel and episode lists. You can still explicitly open a stream in an installed external player. For device testing, compare one ordinary HLS stream, a TS or MKV stream the web player struggles with, and a VOD title with a resume position. Check first picture and sound, play/pause on the remote, track selection, Back, Home and VOD resume. Share the device model, Android or Fire OS version, APK revision, container, codecs if known and the result. Leave out stream URLs, credentials and actual playlist titles. ## Security model - The embedded server listens on `127.0.0.1` only (`TvShellServer`): nothing is exposed on the LAN. `/api` request bodies are capped at 16 KiB (413), the same bound as the upstream web backend, and provider URLs must be `http`/`https`. - Provider requests follow at most five redirects; `Authorization`, `Cookie`, `Proxy-Authorization`, `SN` and `Host` are dropped when a redirect leaves the origin, exactly like the web backend's `ValidatedHttpClient`. - The WebView has file and content access off; the only top-level navigations that leave the shell are `http(s)` links handed to the system (`ACTION_VIEW`), any other scheme is ignored. AndroidX WebKit injects `window.TvShell.postMessage` only at the current loopback origin. The shell handles commands from the main frame of that origin. WebViews without this feature show an update prompt. - The published APK is a **non-debuggable** release build, `allowBackup` is off (the WebView storage holds portal credentials) and remote debugging (`chrome://inspect`) is **opt-in** in the IPTVnator settings. - The native player gets its request from the same trusted main frame. It attaches allowlisted provider headers only to requests on the original stream origin, including redirects, segments and HLS key requests. It keeps response cookies in memory for that origin during the playback session. Native Media3 exception logging is disabled because errors can contain stream URLs. - Native diagnostics and forwarded WebView errors share a redactor. It removes full URLs, including signed paths containing apostrophes, plus credential fields and authorization values before logging or displaying startup diagnostics. Other console levels are consumed without forwarding their original text; each diagnostic is capped at 4,000 characters. - Cleartext traffic is allowed on purpose: the app's own origin is `http://127.0.0.1` and most IPTV portals and streams are plain `http`. - Known limitation: any other app on the device can reach the loopback server and make it fetch provider URLs. There is no secret between the WebView and the server yet. ## Building the APK ### With GitHub Actions (recommended) The `Build TV shell APK` workflow runs on pull requests and `master` pushes that touch `tv-shell/` (artifact only) and on demand (**Actions → Build TV shell APK → Run workflow**; tick `create_release` to also publish a GitHub release `tv-shell-v0.1.0-N`). The release is a **pre-release never marked "Latest"** unless you untick `prerelease`: keep it on in the IPTVnator repository itself, where a Latest release without the desktop updater's files would break auto-update; a fork publishing for its own users can untick it. It builds the PWA (`pnpm nx build web --configuration=pwa`, as the Docker image does), checks the parser fixtures against the installed parser, drives that PWA with the two remote-control suites in Chromium (screenshots are uploaded when one fails), runs the backend tests, assembles the release APK and uploads `iptvnator-tv-shell-0.1.0-.apk`. Signing: without secrets the APK is signed with the **versioned debug key** (`android/app/debug.keystore`, password `android`), which is conventional, not secret, and stable across builds, so newer builds install over older ones. Add the `TVSHELL_KEYSTORE_B64` (base64 keystore), `TVSHELL_KEYSTORE_PASSWORD`, `TVSHELL_KEY_ALIAS` and `TVSHELL_KEY_PASSWORD` secrets for a release key. The `versionCode` is the commit time in minutes, so every build upgrades the previous one. The Android startup mark, legacy and adaptive launcher icons, and TV banner use the shared IPTVnator artwork. Regenerate them with `node tv-shell/tools/gen-brand-assets.mjs`. ### Locally (Android Studio or the command line) ```bash # 1. the PWA, from the repository root pnpm install --frozen-lockfile --ignore-scripts pnpm nx build web --configuration=pwa # 2. copy it into the shell tv-shell/scripts/bundle-pwa.sh dist/apps/web # 3. the APK (JDK 17 + Android SDK 36 + NDK r28c; macOS or x86-64 Linux) sdkmanager "platforms;android-36" "ndk;28.2.13676358" cd tv-shell/android && ./gradlew :backend:check :app:assembleRelease # → app/build/outputs/apk/release/app-release.apk (signed with the debug key) ``` Set `JAVA_HOME` to a JDK 17 installation before running Gradle. Recent Android Studio versions can bundle JDK 25, which this Gradle 8.14.3 wrapper cannot run with (`Unsupported class file major version 69`). AndroidX Browser requires compile SDK 36; the app still targets API 35 and supports API 25 and newer. The Android build compiles the [Media3 FFmpeg audio extension](https://github.com/androidx/media/tree/1.11.1/libraries/decoder_ffmpeg) for ARM and x86 devices. It dynamically links unmodified [FFmpeg 6.1.6 source](https://ffmpeg.org/releases/ffmpeg-6.1.6.tar.xz) under LGPL 2.1 or later. The exact sources and configure flags are pinned in [`scripts/build-media3-ffmpeg.sh`](scripts/build-media3-ffmpeg.sh). The APK workflow includes the matching FFmpeg source archive with its artifacts. ## Installing on a Fire TV stick 1. **Settings → My Fire TV → Developer options**: enable *Apps from unknown sources* (or *Install unknown apps → Downloader*) and, for ADB, *ADB debugging*. 2. **Downloader**: install the *Downloader* app from the Appstore, enter the APK's URL from the GitHub release (right-click the `.apk` asset → copy link), install. 3. **ADB** (from a PC on the same network): ```bash adb connect 192.168.x.x # the stick's IP: Settings → My Fire TV → About → Network adb install -r iptvnator-tv-shell-0.1.0-xxxxxxx.apk ``` 4. Start *IPTVnator*. Add a source: **Sources → Add M3U / Add Xtream / Add Stalker**; OK on a text field opens the Fire TV keyboard. 5. Install **VLC for Android** (Appstore) for `.ts` streams. ## Remote keys | Remote | Action | | --- | --- | | D-pad | move between elements (landing on a text field does not open the keyboard); on the picture: ◀ ▶ seek, ▲ ▼ leave the picture / reach the controls; in a text field the arrows move the caret until it cannot move further; in the source switcher's search: ▲ ▼ highlight a source without leaving the field | | OK | activate; on the picture: fullscreen; on a text field: keyboard. A held OK is one activation | | Back | close dialog/menu → leave fullscreen → previous page → (twice) exit the app; **hold**: IPTVnator settings (remotes without a Menu key) | | Menu | context menu of the focused item; on the picture: open the stream in VLC; **long press**: IPTVnator settings. The HDMI-CEC context-menu key and Y on a game controller do the same | | ▶⏸ ⏪ ⏩ | play/pause, −15 s, +30 s | A physical keyboard can edit a D-pad-focused text field directly. Left and Right adjust the focused timeline or volume slider in fullscreen. Right from a channel goes through its available row actions on the way to the preview. ## Design notes - No LAN server: the backend is embedded in Java (`WebBackend`) with the same contract as `apps/web-backend` (provider-targets / parse / xtream / stalker). `/parse-xml` deliberately answers 501: the PWA does not show the EPG. - Protocol discovery follows the [Xtream contract](../docs/architecture/xtream-portal-compatibility.md#explicit-protocol-discovery). Only an initial refused connection or positively identified TLS wrong-version failure can permit the explicit HTTP probe. Any HTTP response in the redirect chain blocks it; certificate errors and mixed or incomplete TLS evidence never authorize a downgrade. The response exposes only credential-free failure metadata. - Fixed origin `http://127.0.0.1:43330`: the PWA's storage belongs to the origin, so the port of the first start is remembered and never replaced. When another app holds it, the shell retries it briefly, then serves on another port (43330 to 43334) and says so in a toast and in the diagnostics. Each return to the app tries the saved port again and switches back to the user's data as soon as it is free. - The Angular service worker is not served (deliberate 404): the bundle ships inside the APK, caching would only make updates stale. - `tv.js` is loaded **before** the bundle through a same-origin `