You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tvOS: Menu dropdown flickers during playback — currentTime publisher causes parent re-renders #29
Description:
I am building a custom video player UI on top of AetherEngine (tvOS 26, SwiftUI). I used native Menu with .menuStyle(.button) for subtitle/audio track selection during playback. The menu dropdown flickers — the focused item's highlight blinks on and off while the video is playing.
Root cause: AetherEngine publishes @published var currentTime at ~10 Hz (via addPeriodicTimeObserver(forInterval: 0.1)). Any SwiftUI view that observes the engine (via @EnvironmentObject or mirrored through an @ObservedObject PlayerViewModel) re-renders its body on every tick. This causes SwiftUI to recreate the Menu struct, which tears down the native UIMenu on tvOS and rebuilds it — that's the flicker.
I've tried throttling currentTime in our view model, isolating the menu into a separate ObservableObject, .equatable(), UIViewRepresentable wrappers, and suppressing UI updates while the menu is open. None fully fix it — tvOS treats the native UIMenu as a black box that gets torn down on any parent view-tree update.
Questions:
Is there a recommended way to attach custom UI (like track selection menus) alongside AetherEngine on tvOS that avoids this?
Should I be using AVPlayerViewController (the system player) instead of a fully custom UI? Does AetherEngine recommend embedding in AVPlayerViewController?
Is there a way to observe playback time without getting per-frame @published updates — e.g., a lower-frequency callback or a read-only polling API?
Steps to reproduce
Load any video with multiple audio/subtitle tracks using AetherEngine
Build a SwiftUI overlay with a native Menu (.menuStyle(.button)) that reads engine.audioTracks and calls engine.selectAudioTrack(index:)
Observe the engine via @EnvironmentObject or @ObservedObject in the view that contains the Menu
Play the video, focus the menu button, press select to open the dropdown
The focused item inside the dropdown flickers at the engine's currentTime publish rate
AVPlayerViewController Is the default UI for AVPlayer and allows controlling platform native features like reduce loud sounds and enhance dialogue etc. individually during playback.
You’ve uncovered a genuine bug (or rather use case issue)! Thanks for pointing this out.
Your root-cause analysis was exactly right, and this was a design flaw in the engine's API surface, not something a host can work around: as long as currentTime was @Published on the engine itself, every view observing the engine re-rendered at 10 Hz no matter what it actually read.
Fixed as of 92ffa37 with a breaking API change. The continuously ticking values (currentTime, sourceTime, progress, and the live-edge fields) moved to a separate ObservableObject exposed as engine.clock. The engine's objectWillChange no longer fires on clock ticks, so a view that reads engine.audioTracks for a track menu stays untouched during playback and the native Menu no longer gets torn down. This mirrors AVFoundation's own shape: AVPlayer exposes time via addPeriodicTimeObserver, not as observable state.
To your questions:
Custom UI alongside the engine works fine now. Observe the engine for state/tracks/menus, and observe engine.clock only in the leaf view that renders time (or subscribe to engine.clock.$currentTime in your view model).
AVPlayerViewController is a valid approach too (see DrHurt's comment), but it's no longer necessary just to dodge the re-render storm.
engine.clock.$currentTime is a plain Combine publisher, so .throttle(for: .seconds(1), ...) gives you any lower rate you want, and engine.currentTime remains as a read-only polling accessor.
Migration: plain reads (engine.currentTime) compile unchanged; only Combine subscriptions move, engine.$currentTime becomes engine.clock.$currentTime, same for sourceTime and the live-edge fields.
Following up after adopting 3.0.0/3.0.1 — the clock split works exactly as described
(objectWillChange no longer fires on ticks; verified), and it was a necessary fix.
But I want to report back that it was necessary, not sufficient for the original
symptom, and one part of the remaining problem is still engine-side.
What we found after adopting engine.clock
The focused row of an open tvOS Menu blinks whenever any SwiftUI render
transaction runs in the hosting tree — even transactions fully contained in leaf views
that are unrelated to the Menu and don't share state with it. After the clock split,
our chrome no longer re-rendered on ticks, but the menu still flickered because of:
a 1 Hz TimelineView(.periodic) wall clock (sibling view),
a playbar leaf observing engine.clock (10 Hz, later throttled to 1 Hz — still blinked),
a subtitle overlay leaf observing engine.clock at 10 Hz.
Minimal repro: put a SwiftUI Menu next to a TimelineView(.periodic(from: .now, by: 1))
on tvOS 26, open the menu — the focused item blinks once per second. Leaf isolation
doesn't help; only a completely static tree does, which a player UI can't be. We
confirmed the mechanism by elimination: identical ticking with a pure-SwiftUI custom
dropdown → no flicker; freezing every time-driven view while the menu is open → no
flicker; any ticking + Menu → flicker. (Filing this with Apple as a SwiftUI bug too.)
The engine-side part: liveTelemetry is a 1 Hz @Published
While digging we found the engine still has one continuously-ticking published property:
the 1 Hz live-telemetry sampler writes liveTelemetry every second of every session
(VOD included), so any view holding @EnvironmentObject var engine / @ObservedObject re-renders once per second for the whole session — in our app that
was the screen presenting the player, which re-evaluated the player's fullScreenCover (and a UIHostingController.rootView underneath it) every second,
blinking the open menu from outside the player entirely.
This is the same class of issue #29 fixed for the clock. Could liveTelemetry (and
anything else sampled on a timer) move off the engine's ObservableObject surface the
same way — e.g. an engine.diagnostics object, or only published while a stats overlay
opts in? That would make "observe the engine for tracks/state" safe again, which is
what the 3.0.0 release notes promise.
What actually fixed it host-side (maybe worth a docs note)
We ended up using the AVPlayerViewController.transportBarCustomMenuItems architecture:
a UIKit-owned menu button (UIButton with the tvOS 26 .glass() configuration + button.menu + showsMenuAsPrimaryAction, all public tvOS 17+) wrapped in a UIViewRepresentable whose updateUIView replaces the UIMenuonly when the items
actually change:
funcupdateUIView(_button:MenuButton,context:Context){
// Same-value reassignment tears down an open dropdown — skip it.
ifbutton.currentItems!=items{applyMenu(to:button)}}
Same native UI as SwiftUI's Menu (it's the same system menu underneath), but SwiftUI
diffing can never rebuild it while open, so the rest of the player UI ticks freely with
zero flicker. Since custom tvOS chrome on top of AetherEngine seems to be a common use
case, this might be worth a note in the integration docs (or even a small shipped
component) — "observe engine.clock in a leaf" isn't enough on tvOS if the host uses
SwiftUI Menu anywhere in the player.
Happy to share the full wrapper if useful. Thanks again for the quick turnaround on the
clock split — it was a prerequisite for everything above.
Thanks for the exceptionally thorough follow-up, the elimination test isolating Menu + any render transaction is exactly the kind of evidence that makes this actionable.
You're right about liveTelemetry, and it's fixed as of 9d8be9a: it was the last timer-driven @Published on the engine (I audited the rest of the surface; everything else is event-driven). It now lives on engine.diagnostics, a separate EngineDiagnosticsObservableObject mirroring the clock split. Same migration story as 3.0.0: plain reads (engine.liveTelemetry) compile unchanged through a read-only forwarder, and subscriptions move from engine.$liveTelemetry to engine.diagnostics.$liveTelemetry. The sampler keeps running unconditionally (it's cheap, and the forwarder should always be current), but it no longer touches the engine's objectWillChange, so "observe the engine for tracks/state" now holds the way the 3.0.0 notes promised.
Your menu-button pattern is also in the README now (Host setup on tvOS, "SwiftUI Menu in custom player chrome"), with the updateUIView item-diff guard and credit to you. If you can share the Apple feedback number for the Menu + TimelineView repro once filed, I'll add it to the note so other adopters can reference it.
Activity
DrHurt commentedon Jun 9, 2026
AVPlayerViewController with additional menus for the custom subtitles and audio track selection is definitely a good & valid approach.
See this for how to add custom buttons to AVPlayerViewController
https://developer.apple.com/documentation/avkit/customizing-the-tvos-playback-experience
AVPlayerViewController Is the default UI for AVPlayer and allows controlling platform native features like reduce loud sounds and enhance dialogue etc. individually during playback.
You’ve uncovered a genuine bug (or rather use case issue)! Thanks for pointing this out.
superuser404notfound commentedon Jun 10, 2026
Your root-cause analysis was exactly right, and this was a design flaw in the engine's API surface, not something a host can work around: as long as
currentTimewas@Publishedon the engine itself, every view observing the engine re-rendered at 10 Hz no matter what it actually read.Fixed as of 92ffa37 with a breaking API change. The continuously ticking values (
currentTime,sourceTime,progress, and the live-edge fields) moved to a separateObservableObjectexposed asengine.clock. The engine'sobjectWillChangeno longer fires on clock ticks, so a view that readsengine.audioTracksfor a track menu stays untouched during playback and the nativeMenuno longer gets torn down. This mirrors AVFoundation's own shape: AVPlayer exposes time viaaddPeriodicTimeObserver, not as observable state.To your questions:
engine.clockonly in the leaf view that renders time (or subscribe toengine.clock.$currentTimein your view model).engine.clock.$currentTimeis a plain Combine publisher, so.throttle(for: .seconds(1), ...)gives you any lower rate you want, andengine.currentTimeremains as a read-only polling accessor.Migration: plain reads (
engine.currentTime) compile unchanged; only Combine subscriptions move,engine.$currentTimebecomesengine.clock.$currentTime, same forsourceTimeand the live-edge fields.superuser404notfound commentedon Jun 10, 2026
The clock split shipped in release 3.0.0 (https://github.com/superuser404notfound/AetherEngine/releases/tag/3.0.0), migration notes in the release body. Closing; reopen if the flicker persists for you on 3.0.0.
ohjey commentedon Jun 10, 2026
Following up after adopting 3.0.0/3.0.1 — the clock split works exactly as described
(
objectWillChangeno longer fires on ticks; verified), and it was a necessary fix.But I want to report back that it was necessary, not sufficient for the original
symptom, and one part of the remaining problem is still engine-side.
What we found after adopting
engine.clockThe focused row of an open tvOS
Menublinks whenever any SwiftUI rendertransaction runs in the hosting tree — even transactions fully contained in leaf views
that are unrelated to the
Menuand don't share state with it. After the clock split,our chrome no longer re-rendered on ticks, but the menu still flickered because of:
TimelineView(.periodic)wall clock (sibling view),engine.clock(10 Hz, later throttled to 1 Hz — still blinked),engine.clockat 10 Hz.Minimal repro: put a SwiftUI
Menunext to aTimelineView(.periodic(from: .now, by: 1))on tvOS 26, open the menu — the focused item blinks once per second. Leaf isolation
doesn't help; only a completely static tree does, which a player UI can't be. We
confirmed the mechanism by elimination: identical ticking with a pure-SwiftUI custom
dropdown → no flicker; freezing every time-driven view while the menu is open → no
flicker; any ticking +
Menu→ flicker. (Filing this with Apple as a SwiftUI bug too.)The engine-side part:
liveTelemetryis a 1 Hz@PublishedWhile digging we found the engine still has one continuously-ticking published property:
the 1 Hz live-telemetry sampler writes
liveTelemetryevery second of every session(VOD included), so any view holding
@EnvironmentObject var engine/@ObservedObjectre-renders once per second for the whole session — in our app thatwas the screen presenting the player, which re-evaluated the player's
fullScreenCover(and aUIHostingController.rootViewunderneath it) every second,blinking the open menu from outside the player entirely.
This is the same class of issue #29 fixed for the clock. Could
liveTelemetry(andanything else sampled on a timer) move off the engine's
ObservableObjectsurface thesame way — e.g. an
engine.diagnosticsobject, or only published while a stats overlayopts in? That would make "observe the engine for tracks/state" safe again, which is
what the 3.0.0 release notes promise.
What actually fixed it host-side (maybe worth a docs note)
We ended up using the
AVPlayerViewController.transportBarCustomMenuItemsarchitecture:a UIKit-owned menu button (
UIButtonwith the tvOS 26.glass()configuration +button.menu+showsMenuAsPrimaryAction, all public tvOS 17+) wrapped in aUIViewRepresentablewhoseupdateUIViewreplaces theUIMenuonly when the itemsactually change:
Same native UI as SwiftUI's
Menu(it's the same system menu underneath), but SwiftUIdiffing can never rebuild it while open, so the rest of the player UI ticks freely with
zero flicker. Since custom tvOS chrome on top of AetherEngine seems to be a common use
case, this might be worth a note in the integration docs (or even a small shipped
component) — "observe
engine.clockin a leaf" isn't enough on tvOS if the host usesSwiftUI
Menuanywhere in the player.Happy to share the full wrapper if useful. Thanks again for the quick turnaround on the
clock split — it was a prerequisite for everything above.
feat(api)!: split timer-sampled telemetry into engine.diagnostics
superuser404notfound commentedon Jun 10, 2026
Thanks for the exceptionally thorough follow-up, the elimination test isolating
Menu+ any render transaction is exactly the kind of evidence that makes this actionable.You're right about
liveTelemetry, and it's fixed as of 9d8be9a: it was the last timer-driven@Publishedon the engine (I audited the rest of the surface; everything else is event-driven). It now lives onengine.diagnostics, a separateEngineDiagnosticsObservableObjectmirroring the clock split. Same migration story as 3.0.0: plain reads (engine.liveTelemetry) compile unchanged through a read-only forwarder, and subscriptions move fromengine.$liveTelemetrytoengine.diagnostics.$liveTelemetry. The sampler keeps running unconditionally (it's cheap, and the forwarder should always be current), but it no longer touches the engine'sobjectWillChange, so "observe the engine for tracks/state" now holds the way the 3.0.0 notes promised.Your menu-button pattern is also in the README now (Host setup on tvOS, "SwiftUI Menu in custom player chrome"), with the
updateUIViewitem-diff guard and credit to you. If you can share the Apple feedback number for theMenu+TimelineViewrepro once filed, I'll add it to the note so other adopters can reference it.Both ship in 3.2.0.
docs(readme): catch the README up to the 3.x feature set