Back to Feed
article 3m read

Fake cable channels started every show at the opening credits

Tuning into one of my home-made channels always played the first item from the top. Now a channel is a half-hour clock: the hub works out what would be on and how far in, starts there, then reads back where the player really landed and seeks once if it didn't listen. Long movies are still stuck in their first half hour.

Article DepthPractice

Flow

How my channel tune-in works, step by step

  1. 1Wake the TV first

    Run the shared wake-up routine before reading the clock.

  2. 2Read the time once

    Find how far into the current half hour we are.

  3. 3Walk the lineup

    Take away show lengths until the time left fits inside one show.

  4. 4Queue from that show

    Start partway in and keep the shows after it.

  5. 5Skip the double-tap rule

    A channel change is allowed even when something is playing.

  6. 6Check and seek once

    Ask where the player is; if it's far off, seek once, then report honestly.

None of the fake cable channels were live at all. The hub makes each channel a lineup from my own movies and shows, and the guide in the media panel draws it like a TV grid. But tuning in always started the first show from the top. The guide even marked that first show "Now" no matter the time. Every channel, every hour, opening credits.

That's a playlist, not a channel. A channel should already be running when you show up.

Counting down the lineup from the half hour

Now each channel runs on a clock. The schedule is cut into half hours, and the lineup acts as if it started at the top of the current half hour. When I tune in, the hub reads the time once and uses that one reading for everything.

It finds how long ago the half hour began. Then it walks down the lineup, taking away each show's length until the time left fits inside a show. That show is on the air, and the time left is how far in to start. Show lengths get a minimum and a maximum. If the lineup runs out, you start just before the end of the last show.

The queue starts with the show that's on and keeps the ones after it. The guide marks whatever the clock says is on.

Sending the start point

The play endpoint now accepts a start point. It checks the number is sane before anything goes to the TV.

There was a catch. Playback refuses to start if something is already playing, probably so a double tap doesn't start twice. But changing channels always means something is playing. So a request with a start point skips that rule. A double tap might restart a channel now. Fine.

Checking where the player really is

Sending a start point is only asking. I didn't trust the player, so the next change checks. When playback shows up, the hub asks where the player really is. If it's far off, it sends one seek and waits a few seconds. If it still can't confirm, it says the show is playing and the position is still confirming. If the seek itself errors, it says the same thing, so nothing retries and jumps twice.

The test fakes a player that ignores the start point until it gets a seek. That checks my code, not my TV.

Turning the TV on before the math

Earlier, I had moved the wake-the-TV steps into one shared routine. Tune-in runs it first, so the clock is read after the TV is awake.

Lag, then the half-hour reset

There's some lag. The hub reads the clock once, then starts and seeks, and those steps take time. So you always land a little behind where a real channel would be. The bigger annoyance is the math. It resets every half hour, so long shows never get far past their opening stretch.

Keep reading

Pick up a connected idea or branch into a nearby one.

5 paths forward