Skip to content

Fix delayed playback info updates in the audio navigator - #848

Merged
stevenzeck merged 13 commits into
readium:developfrom
stevenzeck:swift6-fixes
Aug 14, 2026
Merged

Fix delayed playback info updates in the audio navigator#848
stevenzeck merged 13 commits into
readium:developfrom
stevenzeck:swift6-fixes

Conversation

@stevenzeck

@stevenzeck stevenzeck commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

I'm leaving this in draft as more issues might creep up. Here is what is changed and why:

  1. In AudioNavigator, makePlaybackInfo was wrapping its completion handler in a Task that awaited currentItem.asset.load. Because this fetch suspends the task until the exact duration is returned, the completion handler was delayed. While not an impact for local files, this caused a several second delay for HTTP streaming where the UI would freeze/fail to update.
  2. Added types: [opened, synchronize, reopened, ready_for_review] to the pull_request check so moving from draft to ready for review triggers checks.

Relates to #758.

@stevenzeck
stevenzeck changed the base branch from develop to swift6 July 8, 2026 16:07
@stevenzeck

stevenzeck commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

I reverted the changes for PublicationOpener for now. If we use NonisolatedNonsendingByDefault, they're not necessary.

@stevenzeck
stevenzeck marked this pull request as ready for review July 31, 2026 19:25
@stevenzeck
stevenzeck requested a review from mickael-menu July 31, 2026 19:26
@stevenzeck stevenzeck changed the title Fixes for Swift 6 Fix AudioNavigator makePlaybackInfo compeltion issue Jul 31, 2026
@stevenzeck stevenzeck closed this Jul 31, 2026
@stevenzeck stevenzeck reopened this Jul 31, 2026
@mickael-menu
mickael-menu changed the base branch from swift6 to develop August 5, 2026 14:27
@mickael-menu
mickael-menu requested a lite review from Copilot August 5, 2026 14:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts AudioNavigator’s makePlaybackInfo to avoid delaying the completion handler while waiting for an exact media duration (notably improving responsiveness for HTTP streaming), and updates the GitHub Actions workflow so CI runs when a PR is moved from draft to “Ready for review”.

Changes:

  • Return MediaPlaybackInfo immediately using the best available duration, then (optionally) refresh with the exact duration once loaded.
  • Introduce a duration cache reset when switching to a new AVPlayerItem.
  • Trigger Checks workflow on pull_request ready_for_review events.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
Sources/Navigator/Audiobook/AudioNavigator.swift Avoids blocking the initial playback-info callback on exact duration load; adds duration caching/reset behavior.
.github/workflows/checks.yml Ensures PR checks run when a draft PR is marked ready for review.
Suppressed comments (2)

Sources/Navigator/Audiobook/AudioNavigator.swift:384

  • The async duration load can start multiple times and the comparison seconds != bestAvailableDuration does not type-check because bestAvailableDuration is a Double?. Also, if you introduce an in-flight task (recommended), ensure it’s set/cleared so repeated calls don’t launch redundant loads.
        if loadDurationAsync, let currentItem = currentItem, exactDurationCache == nil {
            Task {
                if let seconds = try? await currentItem.asset.load(.duration).seconds, seconds.isFinite {
                    guard resourceIndex == self.resourceIndex, currentItem == self.player.currentItem else {
                        return

Sources/Navigator/Audiobook/AudioNavigator.swift:478

  • If you track an in-flight duration load task, it should be cancelled/cleared when swapping the current player item; otherwise an old load could keep running unnecessarily and may block starting a new one until it finishes (depending on the gating logic).
                log(.info, "Starts playing \(link.href)")
                let asset = try mediaLoader.makeAsset(for: link)
                player.replaceCurrentItem(with: AVPlayerItem(asset: asset))
                resourceIndex = newResourceIndex
                exactDurationCache = nil
                loadedTimeRangesTimer.fire()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Sources/Navigator/Audiobook/AudioNavigator.swift
Comment thread Sources/Navigator/Audiobook/AudioNavigator.swift Outdated
@mickael-menu mickael-menu changed the title Fix AudioNavigator makePlaybackInfo compeltion issue Fix delayed playback info updates in the audio navigator Aug 14, 2026

@mickael-menu mickael-menu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @stevenzeck

@stevenzeck
stevenzeck merged commit 1b56d76 into readium:develop Aug 14, 2026
5 checks passed
@stevenzeck
stevenzeck deleted the swift6-fixes branch August 14, 2026 15:31
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.

3 participants