Skip to content

Conversation

@krseager
Copy link
Collaborator

@krseager krseager commented Oct 13, 2025

This PR will implement smooth audio track switching.

Why is this Pull Request needed?

  • Currently Switching audio tracks causes the Audio Buffer to be flushed immediately upon AUDIO_TRACK_SWITCHING event being fired. This leads to buffering being induced every single time when audio track is switched.
  • The solution now provides a new API for setting the nextAudioTrack, which allows you to utilize existing audio track switching behavior OR to use this new API that automatically schedules the next audio track.

Are there any points in the code the reviewer needs to double check?

  • Ensure API documentation is clear
  • Ensure stream-controller and base-stream-controller refactor does not break anything
  • Ensure new AudioSelectionOption is clear and makes sense

Resolves issues:

  • N/A (Let me know if I need to create an issue for this before merging the PR)

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

@krseager krseager marked this pull request as ready for review October 20, 2025 15:33
@robwalch robwalch added this to the 1.7.0 milestone Oct 27, 2025
@robwalch robwalch self-requested a review October 27, 2025 22:27
@krseager krseager marked this pull request as draft November 3, 2025 15:59
Kyle Seager added 3 commits November 5, 2025 12:02
# Conflicts:
#	src/controller/stream-controller.ts
…smux complete, which is before buffering the new audio track's audio segment
@krseager krseager marked this pull request as ready for review November 7, 2025 15:18
Comment on lines 35 to 36
nextAudioTrackSwitchingSafetyDelay?: number;
nextAudioTrackBufferFlushDelay?: number;
Copy link
Collaborator

Choose a reason for hiding this comment

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

AudioSelectionOption is intended to describe the preferred audio of the user, not how to get the option or switch between options. AudioSelectionOption should remain limited to a subset of MediaPlaylist attributes and audio characteristic adjacent properties.

If these new options are necessary, then they should be added to HlsConfig with defaults. Since I don't see any defaults, are they even necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just removed nextAudioTrackSwitchingSafetyDelay & renamed nextAudioTrackBufferFlushDelay to nextAudioTrackBufferFlushForwardOffset to be more accurate and put that into HlsConfig with a default value.

@krseager
Copy link
Collaborator Author

Add unit tests before aproving/merging.

@robwalch
Copy link
Collaborator

robwalch commented Dec 9, 2025

@krseager it looks like all the feedback has been addressed - did I miss anything?

Any ETA on adding tests?

@robwalch robwalch self-requested a review January 8, 2026 19:32
Copy link
Collaborator

@robwalch robwalch left a comment

Choose a reason for hiding this comment

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

Approving with one suggestion for follow-up:

flushImmediate should be added as an optional property in AudioSelectionOption, so that the default behavior can be overridden when using hls.setAudioOption to change audio tracks.

// Make a "smooth" track change to a rendition matching the audio option criteria
// (`lang`, `channels`, etc...)
hls.setAudioOption({ /* track criteria */, flushImmediate: false });

@robwalch robwalch merged commit d10ce09 into video-dev:master Jan 15, 2026
12 checks passed
@github-project-automation github-project-automation bot moved this from Top priorities to Done in HLS.js Release Planning and Backlog Jan 15, 2026
robwalch added a commit that referenced this pull request Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants