Repository navigation
fix(tv): keep background audio moving through its folder while the app is stopped - #876
Conversation
… 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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| 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 } |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
| val player = factory.create(context, target.mediaType) | ||
| player.start( | ||
| prepared.mediaItem.leasedBy(reporter, target.fileId.value, ready.useStartFrom), | ||
| prepared.startPositionMillis, | ||
| playWhenReady = true, |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
…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.






Change
TV background audio moves through its folder while the app is stopped. Part of #708.
Validation
./gradlew verifyand./gradlew :mobile:assembleProductionDebug :tv:assembleProductionDebugUnverified: a destroyed stopped activity still ends playback.