Skip to content

Seek on the loopback-HLS native path resolves clock + state before the seek lands → reported time bounces back through the pre-seek position #37

Closed

Description

@rrgomes

What happened?

On the native (loopback-HLS) VOD path, a seek momentarily reports the target time, then bounces back to the pre-seek position for one or more clock ticks before finally settling at the target when the AVPlayer seek physically lands.

Concrete trace from a backward seek: playhead at 97012 ms → seek to 29345 ms → clock reads 29345 briefly → bounces to 97012 → re-lands at 29345.

Expected: once a seek begins, the reported time moves toward the target and stays there — it should never read the pre-seek position again.

Steps to reproduce

  1. engine.load(url:) a VOD item that routes to the Native AVPlayer / loopback-HLS path (e.g. HEVC or H.264 in MKV).
  2. Let it play to ~97 s.
  3. engine.seek(to: 29.3) (or scrub backward via the transport bar).
  4. Observe AetherClock.currentTime (or the scrub bar): it shows ~29.3 s, snaps back to ~97 s, then returns to ~29.3 s when the seek lands.

Likely mechanism (FWIW — you know the internals best)

seek(to:) calls the native host seek fire-and-forget, then immediately writes clock.currentTime = target and state = .playing (the "optimistically flip back to .playing so the host UI doesn't stick on .seeking" path). On the loopback-HLS source the AVPlayer seek lands multiple seconds later, so the 100 ms addPeriodicTimeObserver reads avPlayer.currentTime (still pre-seek) and overwrites the optimistic value until the seek completes.

Fix direction: await the host seek's completion (the AVPlayer seek(to:completionHandler:) callback) before writing the post-seek clock/state, so .seeking spans the real landing. I have a WIP that does exactly this for the programmatic path — happy to describe it; the same change also enables an accurate in-flight seek signal (filed separately as a capability request, linked below).

Environment

  • AetherEngine: 3.5.0 / dec30dc
  • Host app: Custom / my own integration (a custom tvOS client)
  • Platform: tvOS
  • OS version: tvOS 26.x
  • Device / chip: Apple TV 4K (3rd gen, 2022) and (2nd gen, 2021)
  • Playback path: Native AVPlayer

Source media

Not codec-specific — reproduces with any HEVC / H.264 VOD that takes the loopback-HLS native path; it's a seek-resolution timing issue rather than a decode bug. ffprobe output and a sample available on request.

Error codes / log lines

None — no CoreMedia / AVPlayer / VideoToolbox error is raised. The clock simply bounces through the pre-seek position before settling.

Related

#38 — capability request: expose an accurate in-flight seek signal (isSeeking / seekTarget). The same await-the-landing fix enables it.

Activity

  1. DrHurt commented on Jun 16, 2026

    @DrHurt
    Contributor

    I think I’ve also seen this happen with Sodalite!

  2. superuser404notfound commented on Jun 16, 2026

    @superuser404notfound
    Owner

    Fixed on main (commit 924951e, currently under [Unreleased]).

    Your mechanism analysis was exactly right: seek(to:) drove the native host fire-and-forget, wrote the target clock optimistically, and flipped state back to .playing, so the 100 ms addPeriodicTimeObserver overwrote the optimistic value with AVPlayer's still-pre-seek clock until the loopback seek physically landed.

    What changed:

    • NativeAVPlayerHost.seek is now async and resolves on AVPlayer's seek(to:completionHandler:) callback.
    • While a seek is in flight the periodic observer suppresses its stale currentTime publishing, so the clock holds the target across the landing instead of bouncing.
    • A seekGeneration guard lets a superseding scrub own the final state (AVPlayer reports the abandoned seek finished == false, which is also the rapid-seek coalescing case from Loopback-HLS playback wedges under rapid repeated seeks; recovered clock diverges from the decoded frame #35).
    • seek(to:) awaits that landing before flipping back to .playing.

    Verified off-device with an extended aetherctl seektest probe (a concurrent 20 ms sampler across a single backward seek): no bounce through the pre-seek position. Disabling the suppression flips the probe to FAIL on the same source, confirming it detects the exact bug. The definitive confirmation is latency-dependent (real loopback / slow source / device), so a retest against your repro would be appreciated once it rides the next release.

    Thanks for the precise writeup, it made the fix straightforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions