← notes

Taking the speakers over, and stopping only my own stream

Sep 30, 2026

The chime borrows the speakers for a second. A radio station has to take them over, and give back only itself.

The payment chime borrows every speaker in the house for 0.675 seconds and hands it back. A live radio station cannot work that way. Best FM streams HLS from Costa Rica, and a stream needs a real playback session rather than an overlay clip. The hard part is taking the speakers over, and then stopping only what I started.

The first decision is one group, not one stream per speaker. Separate HLS sessions drift a second or two apart and echo between rooms. So every awake player that can play is pulled into one group, and the stream is loaded into that group once, without transcoding.

The second is to create a session rather than join one. Join or create fails with a session already in progress whenever Spotify or the Sonos app owns the group, and play is supposed to mean take the speakers over.

Stop is where it gets careful. Matching on the station name looks right and is wrong, because the name lingers in the metadata after another app has taken the group back. The match is on the session’s client id. Stop never pauses someone else’s Spotify.

Play also takes a count, adding rooms one at a time in a fixed order. Any room still playing the station from an earlier, bigger play is paused, so play one really means one room.

Volume is set on the group, which scales each speaker in proportion and keeps the balance between rooms. After a write the command reports the level that was asked for, because a read straight after the write can still return the old one.

It runs on the same Worker as the chime. The radio is 191 lines.