Skip to content

Merge #180 (native video Now-Playing) and make the session opt-in - #249

Merged
superuser404notfound merged 4 commits into
mainfrom
merge/pr180-nowplaying
Jul 29, 2026
Merged

superuser404notfound merged 4 commits into
mainfrom
merge/pr180-nowplaying

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

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

NativeAVPlayerHost owns an MPNowPlayingSession bound to its player, plus videoNowPlayingSession / setVideoNowPlayingInfo on the engine, with the staged identity replayed at host creation and onto every fresh AVPlayerItem. It mirrors the AudioAVPlayerHost shape 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 every NativeAVPlayerHost, but that host is consumed by AVPlayerViewController hosts 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, its externalMetadata and its working transport commands, which is the half-working state docs/formats.md already warned about.

So ownership is now the host's call: AetherEngine.ownsVideoNowPlayingSession (default false) is read when a native host is created and threaded into NativeAVPlayerHost, whose nowPlayingSession is 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-runs init, so a session another app took over in the meantime 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, rather than compiling on macOS as a silent no-op.

Tests and docs. VideoNowPlayingOptInTests covers the opt-in gate and the staging semantics. docs/formats.md's advice for custom-transport hosts pointed at holding your own session against currentAVPlayer; it now points at this API, and states plainly that the flag must stay off under AVKit. README and architecture.md document the flag and the asymmetry with the audio path.

Verification

Full suite 1257/1257 green on macOS, -strict-concurrency=complete clean, 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 arm64 green), and running them there is blocked only by the package scheme pulling in aetherctl, which has no Process on tvOS.

🤖 Generated with Claude Code

https://claude.ai/code/session_01At1agC2qU2Y2MX2BKLdT4N

Nathan Perez and others added 4 commits July 21, 2026 16:29
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
Changelog only: the #180 Added bullet joins the #179 one under the same
heading, below main's Fixed section.
@superuser404notfound
superuser404notfound merged commit 0be8922 into main Jul 29, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the merge/pr180-nowplaying branch July 30, 2026 09:57
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