Skip to content

feat: support temporal media fragment URIs#7721

Open
christriants wants to merge 6 commits intovideo-dev:masterfrom
christriants:feat/temporal-media-fragments
Open

feat: support temporal media fragment URIs#7721
christriants wants to merge 6 commits intovideo-dev:masterfrom
christriants:feat/temporal-media-fragments

Conversation

@christriants
Copy link
Copy Markdown
Collaborator

@christriants christriants commented Feb 10, 2026

This PR will...

Add support for W3C Media Fragments URI (temporal dimension) to allow loading and playing specific time ranges of HLS streams using URL fragments like video.m3u8#t=100,110.

New functionality:

  • Parse #t=start,end fragments from source URLs (supports NPT formats: seconds, MM:SS, HH:MM:SS)
  • Set playback start position from fragment start time
  • Automatically pause playback when fragment end time is reached (one-time pause)
  • New MediaFragmentController handles fragment parsing and playback monitoring
  • New MEDIA_FRAGMENT_PARSED and MEDIA_FRAGMENT_END events for application integration

More about MediaFragmentController:

This has been implemented as a separate, optional controller module (can be disabled via config). It listens to MANIFEST_LOADING events to intercept and parse fragments, and attaches media element listeners only when fragment end time is specified. It should automatically detach listeners after pausing.

Why is this Pull Request needed?

Media Fragment URIs are part of the W3C specification and are natively supported by browsers for direct video playback. However, we do not currently support this feature, meaning applications using hls.js cannot use fragment URIs to link to specific time ranges in videos.

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

  • Should temporal media fragments take precedence over startPosition config?
  • Are there any other additional considerations we need to make for live?
  • Should we consider a "reload" button to replay the URI fragment recommended by the spec?

Resolves issues:

Closes #5445

Testing:

Manual testing and demo available at: https://hlsjs-temporal-media-fragments.pages.dev/

Tested scenarios include:

  • VOD streams with valid #t=start,end
  • Start-only fragments (#t=start)
  • End-only fragments (#t=,end)
  • Invalid or out-of-range fragments
  • URLs without fragments (no behavior change)

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

@christriants christriants changed the title Support temporal media fragment URIs feat: support temporal media fragment URIs Feb 10, 2026
Copy link
Copy Markdown
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.

If this were all encapsulated in an optional media fragment controller, then a config class would make it extendable, replaceable, and optional, so that apps configuring HLS.js could ignore media fragments or customize their handling.

Comment thread src/controller/stream-controller.ts Outdated
Comment thread src/hls.ts Outdated
@robwalch robwalch added this to the 1.8.0 milestone Feb 10, 2026
@robwalch robwalch removed this from the 1.8.0 milestone Feb 10, 2026
@christriants christriants force-pushed the feat/temporal-media-fragments branch 7 times, most recently from 1c07e23 to 4c3f772 Compare February 14, 2026 16:45
@christriants christriants force-pushed the feat/temporal-media-fragments branch from 4c3f772 to a7c00b1 Compare February 14, 2026 16:49
@christriants christriants force-pushed the feat/temporal-media-fragments branch from a7c00b1 to 7ce13b6 Compare February 14, 2026 16:57
@christriants
Copy link
Copy Markdown
Collaborator Author

Thanks, @robwalch. I've addressed feedback by creating the media-fragment-controller. This should encapsulate the related logic, and it should be configurable by the application. Appreciate the suggestion.

@robwalch robwalch self-requested a review February 17, 2026 14:18
Comment thread src/controller/media-fragment-controller.ts
Comment thread src/controller/media-fragment-controller.ts Outdated
Comment thread src/controller/media-fragment-controller.ts
Comment thread src/utils/media-fragment-parser.ts Outdated
@robwalch robwalch self-requested a review February 17, 2026 19:13
@robwalch robwalch added this to the 1.8.0 milestone Feb 17, 2026
@christriants
Copy link
Copy Markdown
Collaborator Author

Thanks for the feedback @robwalch! I've addressed your feedback.

While investigating the seeking behavior question, I re-read the W3C Media Fragments URI spec and realized I missed some features including:

  • percent-decoding support - URLs like #t=%31%30,%32%30 (encoded t=10,20) should now work correctly
  • multiple occurrence handling - #t=5&t=10,20 now properly uses the last occurrence (t=10,20) per spec
  • NPT prefix support -#t=npt:10,20 format now supported
  • last valid occurrence -#t=10&t=20 would ignore the previous occurrence and use t=20

I tested these features out in hls.js, and also within browsers.

So the PR has grown a bit because I've added support for these spec-compliant features, but all existing functionality remains unchanged.

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

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Support Media Fragment URIs

2 participants