Repository navigation
fix(session): the Now-Playing card survives a screensaver (Sodalite#149) - #559
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
teardownVideoForBackgroundkeeps theNativeAVPlayerHostalive across the suspension on purpose, because AVKit registers its MediaRemote Now-Playing client once perAVPlayerinstance and never registers again against a swapped one (Code=14 "requires a client callback", issue #15). That teardown also setsplaybackBackend = .none.The foreground reload runs
load(), which decided whether to preserve the host fromplaybackBackend == .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.Issue357BackgroundTeardownSelectionTests, the file that already owns "what a teardown hands the reload that follows it": the realteardownVideoForBackgroundsequence 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.🤖 Generated with Claude Code
https://claude.ai/code/session_015PM3xUJB6ZQyqnmGK1fp6F