Skip to content

[Bug] Seeking to EOF does not update state to .ended, causing play/pause controls to stall #164

Closed

Description

@jihongboo

Summary

When scrubbing or programmatically seeking directly to the end of a VOD media stream (seek(to: duration)), AetherEngine's state does not automatically transition to .ended or .paused. Instead, engine.state remains .playing, causing downstream UI wrappers (such as ZeoPlayerView or custom media controls) to remain stuck on the "Pause" state. Subsequent calls to play() or togglePlayPause() at EOF fail to respond or resume playback because the engine does not automatically seek back to 0.

Expected Behavior

  1. When seeking to or near EOF (targetTime >= duration), AetherEngine should transition its state / playbackPhase to .ended (or .paused) and publish the state update to subscribers.
  2. Invoking play() or togglePlayPause() when the engine is at .ended / EOF should automatically perform an internal seek back to 0.0 seconds before starting playback.

Actual Behavior

  1. Seeking to EOF leaves engine.state set to .playing.
  2. Calling play() or togglePlayPause() while at EOF results in no response (the player remains frozen on the final frame).

Suggested Fix / Implementation Idea

  1. Seek Completion Handling: In seek(to:) completion, verify the landed time / target time. If targetTime >= duration - 0.1 (or at EOF), pause the internal rendering pipeline and update state to .ended.
  2. Auto-rewind on Replay: In play() / togglePlayPause(), check if state == .ended or if the playhead is at EOF. If so, perform an internal seek(to: 0) before setting playback rate to 1.0.

Platform & Environment

  • OS: macOS / iOS / tvOS
  • Engine Version: AetherEngine 5.8.x

Activity

  1. superuser404notfound commented on Jul 20, 2026

    @superuser404notfound
    Owner

    Fixed in 5.15.3.

    Root cause: a programmatic seek(to: duration) never fires AVPlayerItem.didPlayToEndTime (that notification only fires when playback reaches the end on its own), so the seek settled the engine to a phantom .playing while AVPlayer sat parked, frozen on the final frame. And because AVPlayer.play() at end-of-media is itself a no-op, the transport controls then had no way to resume.

    I took a slightly different route than the two suggestions, for one important reason:

    .ended is a terminal state with a deliberate contract (#63). Hosts run their end-of-playback handling off it (mark-watched, autoplay-next, dismiss), and in that state seek() / togglePlayPause() are intentional no-ops so a play press racing an "up next" card cannot silently revive a finished session. Firing .ended on a manual scrub-to-end would misfire all of that, and being terminal it would also strand the playhead with no way to scrub back.

    So instead:

    • Seeking a VOD to (or past) the end now parks it at .paused: honest (nothing is playing), non-terminal (the scrubber stays live, you can scrub back), and replayable.
    • play() / togglePlayPause() now rewind to 0 before resuming when the playhead is parked at end-of-media, so the button works exactly as you expected.
    • .ended (organic completion) stays unchanged.

    Net effect matches your expected behavior (the state no longer stays stuck reporting "playing", and play resumes from the start), while keeping the finished-session semantics intact. Covered by SeekToEndOfMediaTests.

    If you get a chance to retest on 5.15.3 with ZeoPlayerView / your custom controls, let me know how it behaves on your side.

  2. jihongboo commented on Jul 22, 2026

    @jihongboo
    ContributorAuthor

    After checking, the issue has been resolved. Thank you.

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