Repository navigation
Merge #180 (native video Now-Playing) and make the session opt-in - #249
Merged
Merged
Conversation
The audio AVPlayer path already owns an auto-publishing MPNowPlayingSession (AudioAVPlayerHost) because the shared MPRemoteCommandCenter / MPNowPlayingInfoCenter aren't reliably bound to a bare AVPlayer: a background pause drops the app as active Now-Playing and the shared center stops receiving commands. The native VIDEO path had the same exposure with no equivalent - custom-UI hosts (no AVPlayerViewController) got the half-working bare-AVPlayer registration. NativeAVPlayerHost now owns the same sanctioned session pattern: - MPNowPlayingSession bound to the host's AVPlayer, auto-publish ON, so elapsed/rate/duration come from player truth and nobody writes the shared info center. - The session persists with the host across native->native reloads (issue #15), so MediaRemote registration survives the reload seam that previously blanked the system card. - Per-item identity metadata staged via setNowPlayingInfo and replayed onto every fresh AVPlayerItem, so readiness-gate master reloads, media fallbacks, and in-place swaps keep the card. Engine surface mirrors the audio contract exactly: videoNowPlayingSession (hosts register transport commands on its remoteCommandCenter) and setVideoNowPlayingInfo (caller-managed, empty clears, safe before load(), replayed at host creation). Shipped in a production tvOS consumer with a custom player UI; commands and card verified against pause/resume, seek, and gate-reload seams. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
feat(native): own an MPNowPlayingSession for the native video path
Follow-up to the merged PR. The session was created and activated in every
NativeAVPlayerHost, but that host is consumed by AVPlayerViewController hosts
as well as by custom-transport ones, and AVKit owns Now-Playing there through
its own MediaRemote registration. The AudioAVPlayerHost comment quotes the
WWDC22 guidance for exactly this case ("don't use MPNowPlayingSession on tvOS
when using AVKit"); the audio host may ignore it because it is always a bare
AVPlayer, the video host may not. Claiming the session under AVKit costs that
host its identity card, its externalMetadata and its working transport
commands, which is the half-working state docs/formats.md already warned about.
Ownership is now the host's call: AetherEngine.ownsVideoNowPlayingSession
(default false) is read when a native host is created and threaded into
NativeAVPlayerHost, whose session is optional. Identity writes and the per-item
replay are gated on ownership too, so an AVKit host cannot have a second,
host-authored identity fed into AVKit's own publication.
Also hardened:
- becomeActiveNowPlaying() re-asserts ownership on the load path, matching the
audio path. A host preserved across a native->native reload never re-runs
init, so a session another app took over was never claimed back.
- pendingVideoNowPlayingInfo clears in stop() next to pendingExternalMetadata,
so a new session cannot inherit the previous title's card. Surviving
stopInternal stays correct: a reload keeps the card through the seam.
- The public API is behind #if os(tvOS) || os(iOS) like its audio counterpart,
instead of compiling on macOS as a silent no-op.
- VideoNowPlayingOptInTests covers the opt-in gate and the staging semantics.
- docs/formats.md's custom-transport advice now points at this API instead of a
host-held session; README and architecture.md document the flag and why it
defaults off.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At1agC2qU2Y2MX2BKLdT4N
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.
Merges natedogg058's #180 and follows it with the hardening from the review, so the contributed commit lands with its authorship intact.
What #180 adds
NativeAVPlayerHostowns anMPNowPlayingSessionbound to its player, plusvideoNowPlayingSession/setVideoNowPlayingInfoon the engine, with the staged identity replayed at host creation and onto every freshAVPlayerItem. It mirrors theAudioAVPlayerHostshape and is shipping in the contributor's production tvOS app with custom UI.Follow-up commit
The session had to become opt-in. It was created and
becomeActiveIfPossible-ed in everyNativeAVPlayerHost, but that host is consumed byAVPlayerViewControllerhosts too, and AVKit owns Now-Playing there through its own private MediaRemote registration.AudioAVPlayerHost's own comment quotes the WWDC22 guidance for exactly this case ("don't use MPNowPlayingSession on tvOS when using AVKit"); the audio host may ignore it because it is always a bare AVPlayer, the video host may not. Under AVKit an unconditional session costs the host its identity card, itsexternalMetadataand its working transport commands, which is the half-working statedocs/formats.mdalready warned about.So ownership is now the host's call:
AetherEngine.ownsVideoNowPlayingSession(default false) is read when a native host is created and threaded intoNativeAVPlayerHost, whosenowPlayingSessionis optional. Identity writes and the per-item replay are gated on ownership as well, so an AVKit host cannot end up feeding a second, host-authored identity into AVKit's publication.becomeActiveNowPlaying()re-asserts on the load path, matching the audio path. A host preserved across a native->native reload (issue #15) never re-runsinit, so a session another app took over in the meantime was never claimed back.pendingVideoNowPlayingInfoclears instop()next topendingExternalMetadata, so a new session cannot inherit the previous title's card. SurvivingstopInternalstays correct: a reload keeps the card through the seam.The public API is behind
#if os(tvOS) || os(iOS)like its audio counterpart, rather than compiling on macOS as a silent no-op.Tests and docs.
VideoNowPlayingOptInTestscovers the opt-in gate and the staging semantics.docs/formats.md's advice for custom-transport hosts pointed at holding your own session againstcurrentAVPlayer; it now points at this API, and states plainly that the flag must stay off under AVKit. README andarchitecture.mddocument the flag and the asymmetry with the audio path.Verification
Full suite 1257/1257 green on macOS,
-strict-concurrency=completeclean, tvOS Simulator build succeeds. The engine-level tests are behind the same platform guard as the API, so they compile but do not execute on the macOS suite; they typecheck for tvOS (EmitSwiftModule normal arm64green), and running them there is blocked only by the package scheme pulling inaetherctl, which has noProcesson tvOS.🤖 Generated with Claude Code
https://claude.ai/code/session_01At1agC2qU2Y2MX2BKLdT4N