Skip to content

fix(session): the Now-Playing card survives a screensaver (Sodalite#149) - #559

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/nowplaying-after-background
Sep 19, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/nowplaying-after-background

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

What broke

A viewer pauses a film, the Apple TV shows its screensaver, they press a key and the film resumes. The video plays, and the system Now-Playing card is gone: no transport on the iPhone lock screen, no volume from the television's remote. It comes back only by leaving the player and resuming from the detail page (Sodalite#149).

Why

teardownVideoForBackground keeps the NativeAVPlayerHost alive across the suspension on purpose, because AVKit registers its MediaRemote Now-Playing client once per AVPlayer instance and never registers again against a swapped one (Code=14 "requires a client callback", issue #15). That teardown also sets playbackBackend = .none.

The foreground reload runs load(), which decided whether to preserve the host from playbackBackend == .native. On this one path that reads .none, so the load answered "nothing native here" and discarded exactly the instance the teardown had just preserved for it. AVKit then held a registration against a player nobody was using any more.

The change

shouldPreserveNativeHostAcrossLoad(backend:nativeHostSurvives:) asks whether a host is still there rather than which backend is running. Keeping one a load has no use for was already the contract: the software and audio-only dispatch branches each release a preserved-but-unused host before they build.

The in-place item handover (AE#158) keeps reading the running backend. A background teardown has already unloaded the item, so there is nothing left to hand over in place.

Test plan

  • swift test: XCTest 624 passed (1 skipped), swift-testing 3101 passed, exit 0.
  • New tests in Issue357BackgroundTeardownSelectionTests, the file that already owns "what a teardown hands the reload that follows it": the real teardownVideoForBackground sequence is run against an engine holding a host, and the test pins both what it keeps (the host) and what it resets (the backend), then the decision that reads them.
  • Device verification of the screensaver round is open, and is the reporter's retest on Sodalite#149.

🤖 Generated with Claude Code

https://claude.ai/code/session_015PM3xUJB6ZQyqnmGK1fp6F

A tvOS backgrounding tears the video pipeline down and keeps the
NativeAVPlayerHost alive on purpose: AVKit registers its MediaRemote client
once per AVPlayer instance and never registers again against a swapped one
(issue #15). The reload on the way back then threw that host away. It decided
whether to preserve it by reading playbackBackend, which the background
teardown had already reset to .none, so it answered "nothing native here" and
built a fresh AVPlayer.

The viewer came back from the screensaver to a video that played and a dead
Control Center card, with no lock-screen transport and no remote volume, until
they left the player entirely and a new AVPlayerViewController registered from
scratch.

shouldPreserveNativeHostAcrossLoad asks whether a host is still there rather
than which backend is running. Keeping one a load has no use for is already the
contract: the software and audio-only dispatch branches each release a
preserved-but-unused host before they build. The in-place item handover keeps
reading the running backend, because a background teardown has already unloaded
the item and there is nothing left to hand over.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015PM3xUJB6ZQyqnmGK1fp6F
@superuser404notfound
superuser404notfound merged commit f4d1e86 into main Sep 19, 2026
7 checks passed
@superuser404notfound
superuser404notfound deleted the fix/nowplaying-after-background branch September 19, 2026 07:07
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