Files
dsantillan 78b815ae8f
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
El reproductor completo al tocar la barra, y el episodio siguiente al terminar
Tocar la barra abre el reproductor completo, como el de Spotify: portada en grande,
título entero, programa, autor, número de episodio y fecha, una barra que se arrastra,
el tiempo transcurrido y **lo que falta**, −15/+30, anterior y siguiente, y una línea
que dice **"Después: …"** con el nombre del que sigue —o que es el último de la lista.
Es una hoja, no una ruta, por lo mismo de siempre: una pantalla dentro del router se
desmonta al navegar y esto no puede ser lo que corte el audio. Para una emisora el
mismo reproductor no dibuja barra de progreso: una radio en vivo no tiene posición ni
final, y decirlo es mejor que un slider muerto.

Un episodio que termina **sigue con el siguiente** de la lista en la que lo pusiste a
sonar, sin tocar el teléfono; al final de la lista se detiene y el reproductor lo
avisa antes. El que termina queda marcado como escuchado. Los botones de siguiente y
anterior de la **pantalla bloqueada** ahora llegan al elemento de audio, que es donde
alguien con las manos en la barra los va a apretar.

Y dos cosas que aparecieron revisando esto:

- `setRadioNow` llamaba a `setMediaSession`, una función que ya no existe desde que el
  reproductor se unificó (hoy `setStreamSession`). El error quedaba **tragado** por el
  `.catch` del sondeo: la pantalla mostraba el tema —el estado se actualiza antes de la
  línea que falla— y la **pantalla bloqueada nunca se enteraba** del tema que sonaba.
  Ahora hay un test que lo mira y se comprobó por mutación.
- `useUI` tenía **dos definiciones** de `setRadioVolume` y `setRadioNow`: al insertar el
  bloque de podcasts había quedado duplicado el final del bloque de radio, y en un
  objeto literal la última gana en silencio. Una copia era código muerto que se leía
  como vivo — y fue la que hizo que el primer intento de comprobar lo anterior "pasara".

Tests nuevos: useUI.podcast.test.js (16, con el reproductor burlado emitiendo lo que
emite un navegador: ended → siguiente, time → reloj, paused → posición guardada),
NowPlaying.test.jsx (13) y el toque en la barra en PlayerBar.test.jsx.
2026-09-23 21:40:17 -04:00

8.6 KiB

Radio

Live stations, for the hour you're in the gym. Open Música → Radio, pick a genre, press a station, and it plays while you train — across screens, with the screen locked and the phone in your pocket.

It is radio, not a music library: you don't pick the song, and nobody has to. That is the whole reason it exists next to the Apple Music playlists on the same screen — one is what you listen to on purpose, the other is what plays while you count reps.

What is playing

There is also a search box above the tabs, and it searches the directory rather than the page you are looking at: jazz is every jazz station radio-browser knows, not the jazz stations that happened to be in the genre on screen. Results are ordered by the name first — a station called "Jazz 24" comes before one with "jazz" buried in a forty-character marketing name — and then by how many people listen. The curated channels and mixes that match come first of all: no advertising, and a stream already known to work.

Chips pick a genre. Ten of them: Workout / Rave, Techno / House, R&B / Soul, Latina, Hip-Hop, Reggae, Chill, Jazz, Rock, Electrónica. Each one is a list of SomaFM channels (curated by hand — a machine cannot know that Seven Inch Soul is the R&B one), the Radio Paradise mixes that fit, and the radio-browser tags that fill in the rest.

The ad-free ones come first in every genre: SomaFM is a listener-supported, commercial-free network of 46 channels, and Radio Paradise is four hand-mixed ones. Both publish their stream as a playlist .pls, which api/radio.js reads rather than guessing a bitrate into a URL — that is what makes the same code work for every channel, including the ones added after this was written.

Behind them is radio-browser, a public, community-run directory of tens of thousands of stations. It is filtered hard: HTTPS only (a page served over HTTPS cannot play an http:// stream at all — the browser blocks it as mixed content, so offering one would be offering a station that silently does nothing), hidebroken=true, ordered by how many people actually listen to it.

Where the audio goes

From the station to your phone. Never through this server.

The api hands out the list — each station with its stream URL already resolved — and after that it sees nothing: no traffic, no disk, no byte of audio. On a small VPS that is the difference between a feature and a bandwidth bill, and it is also why nothing here ever downloads, records or keeps a copy of anything.

Two kinds of request do reach out from the server, and both are for the list and its caption:

Call To Why
channel list + .pls somafm.com to resolve a channel into a stream URL
bytagexact search all.api.radio-browser.info the directory's stations per genre
now_playing api.radioparadise.com the cover and the track for the bar

All of them are cached for ten minutes, so opening the screen twice is one round of requests. Every outgoing call goes through one function with a host allowlist (RADIO_HOSTS) — the api container sits on the owner's own network, so the set of hosts it will talk to is a security boundary, not a convenience.

So the server does see something: which genre chip was pressed, and — only for the two sources that publish what they play — which station the bar is asking about, once every 45 seconds while it plays. Nothing is written down: those are requests, not records, and there is no table, log or file where listening would accumulate. (The request log in the admin dashboard is the activity log, and it carries sign-ins and admin actions, not this.)

Why the stream URL arrives in the list

iOS only lets audio start inside the gesture that asked for it. Anything asynchronous between the finger and the play() — a fetch, a state update, a re-render — is a press that does nothing, with no error anywhere. So the list arrives complete: by the time a station has been drawn on the screen, its stream URL is already in the object the row holds, and the press calls play() synchronously.

The <audio> element lives in frontend/src/lib/player.js, outside React, as a module-level singleton — the same element the podcasts use, which is also what keeps a station and an episode from ever playing at once. An element owned by a component is unmounted when the component is, which is how a player stops the moment you change screens — and changing screens mid-session is the normal case here, not the edge case.

The bar, and the lock screen

While something is playing, a bar sits above the tab bar (the same place and the same glass as the rest timer, on purpose — a second floating bar with its own look reads as a second app):

  • the station, and what it says it is playing
  • pause — keeps the station, so the same one is still there after the rest
  • stop — takes the bar and the station away

Tapping the bar itself opens the full player — the logo at size, the station, its genre, what it says it is playing, and pause/stop — with no scrubber and no clock, because a live stream has no position and no end, and a slider that does nothing is worse than a sentence that says so.

Media Session is what puts the station, the track and the controls on the lock screen and in the car, and it is what makes "screen off, phone in pocket" work: the audio is played by the browser underneath the page, not by the page's timers. Those timers — the 45-second poll for what is playing — are suspended while the screen is locked, so the caption simply stops moving until you look again. It is a caption; the music is unaffected.

On the native Android/iOS shells the same rules apply, with one addition: keeping audio alive under a locked screen in a WebView needs UIBackgroundModes: audio (iOS) and a foreground service (Android) in the shell's own config. Neither is set today — that is described in docs/MOBILE.md, and it only affects the packaged builds, not the PWA.

When the radio isn't there

Two situations look like a bug and are not, so the screen says which one it is instead of showing a request that failed:

  • Nobody is signed in. Guest mode is client-side only and never talks to the api, and the station list is the server's job — so the section says the radio needs a profile. No request is made.
  • The api is older than the app. They ship separately: web is rebuilt from source on every deploy, while the api's code lives inside its container, so a deploy can leave a new screen on top of an api that has never heard of /api/radio. GET /api/config lists what that api can do (features, and this build answers radio), so "old server" is detectable — the section says so, quietly, rather than offering chips that 404. The same list is what keeps the Salud screen from blaming the data when it is really the container.

Saving a station

The star on a row saves the station to your profile (music.stations), and saved ones are pinned above the list. They are stored with the rest of your profile's client state — they contain nothing about your listening, just the station you liked.

What this deliberately is not

  • Not a YouTube/Spotify front end. Ripping streams or playing someone else's catalogue through an unofficial API breaks those services' terms and this project's licence is AGPL; the honest version of "radio" is radio.
  • Not a proxy. No endpoint here relays audio. Every /api/radio response is JSON, and the routes are session-gated so the list cannot be borrowed by somebody else's page.
  • Not a downloader. There is no record button and no cache of audio anywhere.
  • Not HLS. Stations that only stream HLS are skipped: playing them in a browser needs hls.js, and a dependency-light project does not take a media stack on for a feature whose whole point is that it makes no new dependency necessary.

Credits and licences

  • SomaFM — listener-supported, commercial-free; the channels used here are theirs, and their stream URLs are resolved through their own public .pls.
  • Radio Paradise — listener-supported, and the now_playing endpoint that gives the bar its cover art.
  • radio-browser — the directory itself is AGPL-3.0, same family as this project, and it is the reason the long tail of stations is reachable at all.

These are third-party services this app does not control: a station that goes off the air disappears from the list on the next refresh, and a genre that comes back thin is the directory having a bad day, not the app.