Skip to content

fix(tv): keep background audio moving through its folder while the app is stopped - #876

Merged
altaywtf merged 6 commits into
mainfrom
fix/708-tv-background-queue-advance
Nov 20, 2026
Merged

altaywtf merged 6 commits into
mainfrom
fix/708-tv-background-queue-advance

Conversation

@altaywtf

@altaywtf altaywtf commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Change

TV background audio moves through its folder while the app is stopped. Part of #708.

Mi Box, app on Home Session plays
Track 1 ends track 2, to its end
Track 2 ends track 3
Previous, previous, then next track 2, then track 3
Back in the app Mini player, track 2 Track 2 ended
  • One system session spans the queue, so Android 16 no longer mutes the next track.
  • A track stops once the next loads or fails.
  • Off-screen tracks report their end or failure.

Validation

  • Code changes: ./gradlew verify and ./gradlew :mobile:assembleProductionDebug :tv:assembleProductionDebug
  • Proof for each matching row of the AGENTS.md proof map

Unverified: a destroyed stopped activity still ends playback.

… stopped

Compose pauses its frame clock on ON_STOP, so a player that lives in
TvReadyPlayer's composition can't create the next track's player. A
finished track behind Home went silent, and the system's next and
previous were gated off while stopped.

Background audio's player, session and folder queue now live in
TvPlaybackQueue, outside the screen's composition. It publishes through
TvPlaybackService, advances a finished track, and serves the system's
skip and play controls itself while stopped; the screen adopts the
queued player when it returns and forwards session commands while
attached. Video and audio without a background path keep the screen-owned
player and its STARTED gating.
Publishing a new session per track removed the old one, which dropped
the playback service out of the foreground. Android 16 then refused the
foreground restart and the next track's audio focus from the background,
so the second track played muted and the third paused. The queue now
publishes one session and swaps its player.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T16:20:18.602810Z e99a3f9 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@altaywtf altaywtf mentioned this pull request Nov 20, 2026
4 tasks done

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 58bf633a94

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +77 to +80
fun attach(player: Player, skip: (Boolean) -> Unit, setPlaying: (Boolean) -> Unit): Closeable {
val attached = Screen(player, skip, setPlaying)
screen = attached
return Closeable { if (screen === attached) screen = null }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop the outgoing track when switching playback targets

When the user skips an audio track before it finishes, NextChosen replaces the ready screen with loading content. Disposing that screen now only detaches it from the queue; the outgoing player is released only when take receives a successfully resolved replacement. The old track therefore keeps playing throughout resolution and continues behind the error screen if resolution fails, whereas the previous screen-owned implementation released it immediately. Reconcile the retained player's playback with controller target/content changes so a failed switch cannot leave the previous track audible.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an issue: NextChosen moves the controller to loading for another file, and the queue's state collector pauses the held player on that (!ready && playing.target.fileId != held.fileId -> held.player.pause()). A failed resolve reaches PlaybackContent.Failed, which drops it. The outgoing track never keeps playing.

Comment on lines +108 to +112
val player = factory.create(context, target.mediaType)
player.start(
prepared.mediaItem.leasedBy(reporter, target.fileId.value, ready.useStartFrom),
prepared.startPositionMillis,
playWhenReady = true,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Carry the selected playback speed into background tracks

If the user selects a non-default playback speed and then leaves the app, every subsequent track created here starts at the factory default speed. The foreground path applies the retained TvPlaybackOptions.speed before starting each player, but this new background path has no equivalent; the selected speed is only restored when the screen returns and adopts the player. Preserve the queue's playback options when creating replacement players so advancing in the background does not unexpectedly change listening speed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a regression: playback options are keyed per file (rememberSaveable(state.target.fileId.value, ...) in TvPlayerScreen), so a new track starts at default speed in the foreground too. Background tracks match that.

The background queue kept the previous track playing while the next one
loaded or failed to open, handed a failed player back on retry, and left
the screen on a released player when the queue replaced the same file
while the app was stopped.
@altaywtf

altaywtf commented Nov 20, 2026 •

Copy link
Copy Markdown
Member Author

Mi Box (Android TV 9) pass on 4ab5cf1b: background queue, system skips, mini player, and video skips all work.

Return after system Prev/Next while stopped Mini player on 02 Mini player advanced to 03
  • App stopped (launcher in front): 01 → 02 → 03 advanced at track length, with one system session the whole time; the queue stops after 03.
  • System Next and Previous with the app stopped: 02 → 03, Previous restarts after 3 s, a second Previous goes to 02.
  • Return after 02 → 03 → 02: the screen plays the live 02 player (0:15, then 0:21), not the released one.
  • Video: paused FF/FF/REW moved 31.4 → 41.4 → 51.4 → 41.4 s; play resumed.
  • Not covered: a track failing to open while the app is stopped (unit test only).
More captures

…pped

A player the background queue creates while the app is stopped had only
an end listener: a load or decode failure never reached the controller,
so expired-link recovery and diagnostics never ran, and a track ending
there never sent playback_ended. The queue now reports both through the
route's failure handler and the controller's analytics reporter.

The folder lookup also keys on the file id again, so a same-file target
change no longer drops and refetches the neighbours.
@altaywtf

altaywtf commented Nov 20, 2026 •

Copy link
Copy Markdown
Member Author

Mi Box, e99a3f9a: three 15 s tracks played from Home while the app was stopped; all three show Watched on return.

@altaywtf
altaywtf merged commit 296c9f1 into main Nov 20, 2026
5 checks passed
@altaywtf
altaywtf deleted the fix/708-tv-background-queue-advance branch November 20, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant