Skip to content

fix: preserve vhs-json initial ABR selection and pre-buffer paused players#1609

Draft
kpoojari-li wants to merge 3 commits into
videojs:mainfrom
kpoojari-li:fix/vhs-json-initial-abr-selection
Draft

fix: preserve vhs-json initial ABR selection and pre-buffer paused players#1609
kpoojari-li wants to merge 3 commits into
videojs:mainfrom
kpoojari-li:fix/vhs-json-initial-abr-selection

Conversation

@kpoojari-li

Copy link
Copy Markdown

Description

Fixes #1608.

Fixes two coupled vhs-json bugs.

  1. Initial ABR selection was discarded. PlaylistLoader.setupInitialPlaylist used !this.request to decide whether ABR had already selected a playlist. For vhs-json, media() resolves via a no-XHR fast path that sets this.media_ without ever setting this.request, so the guard was always true and the selection was overridden back to playlists[0]. Now also checks this.media_.

  2. Paused players stopped pre-buffering. That playlists[0] override had been accidentally restarting the segment loader. Since vhs-json fires loadedmetadata synchronously (before handleUpdatedMediaPlaylist pauses the loader), removing the override left paused preloading players with no segment downloads. We now explicitly resume the loader after handleUpdatedMediaPlaylist, gated to VoD + preload to mirror the existing loadedmetadata pre-buffer condition (media.endList && tech_.preload() !== 'none'). Live behavior is unchanged.

Why this wasn't caught earlier: the demo manifest (scripts/dash-manifest-object.json) had only a single playlist, so the playlists[0] override was a no-op there — with one variant there is no other selection for ABR to make, so the bug was invisible on the demo page. This PR updates that manifest to multiple resolved variants, which makes the issue reproducible and reviewable on the demo page.

Specific Changes proposed

  • src/playlist-loader.js: guard is now if (!this.request && !this.media_).
  • src/playlist-controller.js: after handleUpdatedMediaPlaylist, call mainSegmentLoader_.load() for vhs-json VoD when preload !== 'none'.
  • scripts/dash-manifest-object.json: updated to a multi-variant resolved manifest. The previous demo manifest had only a single playlist, so neither bug could surface on the demo page — with one variant there is no alternative for ABR to select, so the playlists[0] override was never observable. Adding multiple resolved variants makes both issues reproducible on the demo page and gives reviewers a way to verify the fix.
  • test/playlist-loader.test.js and test/playlist-controller.test.js: tests that fail without the fix and pass with it.

Testing Done

Added unit tests in both test/playlist-loader.test.js and test/playlist-controller.test.js that fail on main and pass with this change (verified by reverting the source fixes and confirming only the two new tests fail). Also verified on the demo page with the updated multi-variant manifest.

Before — on a throttled (3G) connection the player fetches playlists[0] (1920×1080, ~9.9 Mbps) first, then ABR corrects down to 320×180:

issue-compressed.mp4

After — the ABR-selected variant is honored from the start, and a paused preload="auto" player pre-buffers segments:

fix-compressed.mp4

Requirements Checklist

  • Bug fixed
  • Unit Tests updated

Kushal Raghav Poojari and others added 3 commits May 31, 2026 00:35
…urces

For vhs-json sources, PlaylistLoader.media() resolves via a no-XHR fast path
that sets this.media_ without setting this.request. setupInitialPlaylist used
`!this.request` as the signal that ABR had not yet selected a playlist, so for
vhs-json it always fell back to playlists[0], overriding ABR's choice. Also
check this.media_ so an existing selection is preserved.

Updates scripts/dash-manifest-object.json to a multi-variant resolved manifest
so the issue reproduces on the demo page.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
vhs-json fires loadedmetadata synchronously, so the segment loader starts
before handleUpdatedMediaPlaylist pauses it. With the initial-selection fix,
the playlists[0] override no longer accidentally restarts it, so paused players
with preload enabled stopped pre-buffering. Explicitly resume the loader after
handleUpdatedMediaPlaylist, gated to VoD + preload to mirror the existing
loadedmetadata pre-buffer condition; live behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

vhs-json: initial ABR playlist selection is overridden, and paused players don't pre-buffer

1 participant