Skip to content

Fix calculation of max buffered time#4109

Open
SergioEstevao wants to merge 1 commit into
trunkfrom
sergio/fix_buffer_loading_indicator
Open

Fix calculation of max buffered time#4109
SergioEstevao wants to merge 1 commit into
trunkfrom
sergio/fix_buffer_loading_indicator

Conversation

@SergioEstevao

@SergioEstevao SergioEstevao commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

| 📘 Part of: # |
|:---:|

Fixes PCIOS-

Updates the calculation of the loaded ranges to take in account the maximum range loaded and not only the first range that is larger than the the current play position

To test

  1. Open an podcast with a longer episode that is not downloaded
  2. Tap play on the episode
  3. Watch the loading bar on the progress indicator on the mini-player and see if buffering bar updates correctly
  4. Check if playing continues correctly

Checklist

  • I have considered if this change warrants user-facing release notes and have added them to CHANGELOG.md if necessary.
  • I have considered adding unit tests for my changes.
  • I have updated (or requested that someone edit) the spreadsheet to reflect any new or changed analytics.

@SergioEstevao SergioEstevao added this to the 8.9 ❄️ milestone Apr 6, 2026
@SergioEstevao SergioEstevao added the [Type] Bug Used for issues where something is not functioning as intended. label Apr 6, 2026
@SergioEstevao SergioEstevao modified the milestones: 8.9 ❄️, 8.10 Apr 9, 2026
@SergioEstevao SergioEstevao changed the base branch from release/8.9 to trunk April 9, 2026 21:19
@pocketcasts pocketcasts modified the milestones: 8.10, 8.11 Apr 14, 2026
@pocketcasts

Copy link
Copy Markdown
Contributor

Version 8.10 has now entered code-freeze, so the milestone of this PR has been updated to 8.11.

@SergioEstevao SergioEstevao marked this pull request as ready for review April 21, 2026 16:27
@SergioEstevao SergioEstevao requested a review from a team as a code owner April 21, 2026 16:27
@SergioEstevao SergioEstevao requested review from Copilot and kean and removed request for a team April 21, 2026 16:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates DefaultPlayer’s buffering calculation so the app can derive a better “max buffered” value from AVPlayer’s loadedTimeRanges, improving how buffering progress is represented during streaming playback.

Changes:

  • Adjusts futureBufferAvailable() to scan all loadedTimeRanges and track the maximum buffered end time beyond the current playhead.
  • Returns the computed maximum buffered value instead of early-returning on the first qualifying range.

}

return 0
return maxTime

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

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

futureBufferAvailable() appears to be used as “seconds of playable buffer remaining” (e.g. MiniPlayer computes buferredAmount = buffered / (duration - currentTime), and other players return duration() - currentTime()). This implementation now returns an absolute media time (range.start + range.duration) rather than the buffer-ahead interval, which will under/over-report buffer and can skew the UI. Consider returning max(0, maxEndTime - upTo) (and optionally clamping to duration() - upTo).

Suggested change
return maxTime
return max(0, maxTime - upTo)

Copilot uses AI. Check for mistakes.
Comment on lines 134 to +135
let rangeBuferred = range.timeRangeValue
if (CMTimeGetSeconds(rangeBuferred.start) + CMTimeGetSeconds(rangeBuferred.duration)) > upTo {
return CMTimeGetSeconds(rangeBuferred.duration)
let rangeMaxTime = CMTimeGetSeconds(rangeBuferred.start) + CMTimeGetSeconds(rangeBuferred.duration)

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

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

Typo in local variable name: rangeBuferred should be rangeBuffered (or similar) for readability and to avoid propagating the misspelling.

Copilot uses AI. Check for mistakes.

@kean kean left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The change seems straightforward and low-risk.

I got the following message by running an automated review locally – worth addressing?

there's a subtle semantic change that's worth flagging. DefaultPlayer.swift:134-135 now
  returns rangeMaxTime (an absolute time within the episode), but the old code returned
  rangeBuferred.duration (a length of buffered content). The sole caller at
  MiniPlayerViewController.swift:239-242:

  let amountBuferred = PlaybackManager.shared.futureBufferAvailable()
  if amountBuferred > 0 {
      playbackProgressView.buferredAmount = CGFloat(amountBuferred / (duration - currentTime))
  }

  divides the returned value by remaining time. Neither the old (duration) nor the new (end) value is
  really the "amount buffered ahead" that the name implies — the correct expression would be maxTime -
  upTo. For typical progressive streaming (one range starting at 0), both old and new produce the same
  number, so this PR doesn't regress the UI, but the display can still overshoot once currentTime > 0.
  Consider returning maxTime - upTo to align with the function's name and the EffectsPlayer counterpart
  (duration() - currentTime()).

for range in loadedTimeRanges {
let rangeBuferred = range.timeRangeValue
if (CMTimeGetSeconds(rangeBuferred.start) + CMTimeGetSeconds(rangeBuferred.duration)) > upTo {
return CMTimeGetSeconds(rangeBuferred.duration)
let rangeMaxTime = CMTimeGetSeconds(rangeBuferred.start) + CMTimeGetSeconds(rangeBuferred.duration)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(nit) It'd probably be more readable using a functional style with map followed by max() ?? 0

@pocketcasts pocketcasts modified the milestones: 8.11, 8.12 Apr 27, 2026
@pocketcasts

Copy link
Copy Markdown
Contributor

Version 8.11 has now entered code-freeze, so the milestone of this PR has been updated to 8.12.

@pocketcasts pocketcasts modified the milestones: 8.12, 8.13 May 11, 2026
@pocketcasts

Copy link
Copy Markdown
Contributor

Version 8.12 has now entered code-freeze, so the milestone of this PR has been updated to 8.13.

@pocketcasts pocketcasts modified the milestones: 8.13, 8.14 May 25, 2026
@pocketcasts

Copy link
Copy Markdown
Contributor

Version 8.13 has now entered code-freeze, so the milestone of this PR has been updated to 8.14.

@pocketcasts pocketcasts modified the milestones: 8.14, 8.15 Jun 8, 2026
@pocketcasts

Copy link
Copy Markdown
Contributor

Version 8.14 has now entered code-freeze, so the milestone of this PR has been updated to 8.15.

@pocketcasts pocketcasts modified the milestones: 8.15, 8.16 Jun 23, 2026
@pocketcasts

Copy link
Copy Markdown
Contributor

Version 8.15 has now entered code-freeze, so the milestone of this PR has been updated to 8.16.

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

Labels

[Type] Bug Used for issues where something is not functioning as intended.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants