Skip to content

Adds Captions to AV Component and Fixes HLS Streaming - #1937

Open
K8Sewell wants to merge 57 commits into
devfrom
issue-1380-reintegrate-av-component-plus-captions
Open

K8Sewell wants to merge 57 commits into
devfrom
issue-1380-reintegrate-av-component-plus-captions

Conversation

@K8Sewell

@K8Sewell K8Sewell commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Description of what you did:

  • AV Component can now handle captions
  • Shared tooling between AV Component and Media Element
  • HLS streaming behavior consolidated and repaired
  • Added tests and updated documentation

Relevant Issue

#1926

PR Contents

90% of the files changed in this PR are the addition of test fixtures and tests. Most changes revolve around the AV Component and Media Element.

Draft Release Notes

Details

Audio and video

Both of UV's audio and video players (the AV extension, for manifests with ranges, and the MediaElement extension, for those without) now have captions, play streams more reliably, and have accessible controls. See Audio and Video for the details.

Captions

  • Both players show captions from WebVTT (text/vtt) and SRT (text/srt) files, whether the manifest gives them as a supplementing annotation (IIIF Cookbook recipe 0219), including a Choice of languages (recipe 0074), as a rendering of the canvas, or alongside the media in its painting annotation.
  • A captions button opens a menu for choosing the language (the user's own first) and the colours. Captions are off until a language is chosen.
  • UV offers five colour combinations, each with at least 7:1 (WCAG AAA) contrast. You can offer your own with the new captionStyles option on avCenterPanel and mediaElementCenterPanel.
  • The chosen language and colours are remembered in localStorage (uv-caption-preferences), and carry over to other canvases and manifests.
  • Caption files are fetched by the browser, so their server must send CORS headers.

Streaming (HLS and MPEG-DASH)

  • Something plays wherever it can. When a manifest offers the media in more than one version (e.g. a Choice of formats), both players try each in turn until one plays: HLS, then MPEG-DASH (except in Safari), then any other format, then a version with no format, then HLS by the other way (the browser's own player or hls.js).
  • No CDN. UV now includes hls.js and dash.js, and loads each only when media needs it. The MediaElement player used to fetch them from cdn.jsdelivr.net. If the page that hosts UV has already loaded its own copy (as window.Hls or window.dashjs), UV uses that instead of loading its own; a page's own hls.js is tried first, even in Safari.
  • Less data. hls.js and dash.js only fetch renditions the player is big enough to show.
  • Clearer errors. When nothing can be played, the MediaElement player now shows a message, as the AV player did. Where the only way to play an HLS stream was hls.js, and its server sends no CORS headers (e.g. in Firefox, which has no HLS player of its own), the message says so. The new hideMediaError option on mediaElementCenterPanel hides it, as the existing one does on avCenterPanel.

Accessible controls

  • Every control in both players has a label, and a tooltip, in the user's language.
  • Buttons are at least 44 by 44 pixels (WCAG 2.1 success criterion 2.5.5, AAA), and the controls fit any screen size. The AV player's controls wrap onto more rows on narrow screens.
  • The timeline and volume are sliders that screen readers announce by name, with their values (e.g. "01:05 of 09:32"), and can be moved with the keyboard.
  • The MediaElement player's volume slider is always shown. The new hideVolumeOnTouchDevices option hides it on touch devices. On iOS and iPadOS, which don't let pages set the volume, only the mute button is shown.

Images with audio and video

Both players now choose the image shown with audio or video the same way: a placeholderCanvas before the media plays (recipe 0013), an accompanyingCanvas while it plays (recipe 0014), and otherwise a thumbnail. A posterCanvas, from drafts of IIIF Presentation 3, is read as a placeholderCanvas.

Translations

The players' and the captions menu's text is translated into every language UV ships (cy-GB, en-GB, fr-FR, pl-PL and sv-SE). If you maintain your own build of UV with your own locale files, add the new keys from src/locales/en-GB.json to them: a key a locale file doesn't have appears in the viewer as the key itself, e.g. $captionsOff instead of "Off".

Bugs fixed

Bug Player
A pause soon after another could cancel the next press of play AV
The clock jumped ahead after buffering, skipping part of the media AV
The clock moved on while paused after a seek AV
Choosing another track stopped playback Both
Thumbnails were cut off MediaElement
A clip placed in part of a canvas (#xywh=) was shown in the wrong place, in auto-advance playback AV
Fractions of a second were dropped from a clip's times (#t=), e.g. a clip from 1.5 seconds into its file started at 1 second AV

@demiankatz demiankatz 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.

@K8Sewell, I played with our https://digital.library.villanova.edu/Item/vudl:829943/Manifest manifest on this branch a bit more and have a couple of comments:

1.) For some reason, loading the manifest intermittently fails. About 30% of the time, I see the "cannot load media" message (with the link to download), but the rest of the time it works normally.

2.) I think the caption control may need a little more thought -- I was convinced that captions were broken because when I set caption colors, the captions didn't come up -- but that's because I was setting the colors while captions were turned off! I wonder if we should disable the color options when captions are disabled to prevent this misconception....

I've started looking at the code a little bit, too -- so far I like what I see (though I'm afraid I can't promise to look thoroughly at this large volume of tests!). I'll review more files in more depth after we finish this part of the conversation. :-)

@K8Sewell

Copy link
Copy Markdown
Contributor Author

@K8Sewell, I played with our https://digital.library.villanova.edu/Item/vudl:829943/Manifest manifest on this branch a bit more and have a couple of comments:

1.) For some reason, loading the manifest intermittently fails. About 30% of the time, I see the "cannot load media" message (with the link to download), but the rest of the time it works normally.

2.) I think the caption control may need a little more thought -- I was convinced that captions were broken because when I set caption colors, the captions didn't come up -- but that's because I was setting the colors while captions were turned off! I wonder if we should disable the color options when captions are disabled to prevent this misconception....

I've started looking at the code a little bit, too -- so far I like what I see (though I'm afraid I can't promise to look thoroughly at this large volume of tests!). I'll review more files in more depth after we finish this part of the conversation. :-)

Thank you for taking an initial look. Yes, I know, :) fair few tests. I did adjust the color menu for the captions so that now it should be a little more obvious when the captions are off. Interested to know what you think!

@demiankatz

Copy link
Copy Markdown
Contributor

Thank you for taking an initial look. Yes, I know, :) fair few tests. I did adjust the color menu for the captions so that now it should be a little more obvious when the captions are off. Interested to know what you think!

Thanks, @K8Sewell, this is definitely an improvement!

One other detail we might want to think about (though there's no perfect answer, and I don't seriously object to how it behaves today) is the closing behavior of the caption controls. It feels just a little strange to me that the caption pop-up closes as soon as I choose something. If I want to change the captions and change the color, I have to open the control twice because it changes after each selection I make. Would it possibly be better to have the control toggle open and closed with the caption button, but stay open when selections are made? (As I said, I'm not sure I prefer it differently than it is currently implemented, but just raising the idea for consideration).

@demiankatz demiankatz 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.

I put a few more minutes into review here and chipped away at more files, though I still have about 50 to go. I'll try to find time for more later in the week. In the meantime, see below for a new question:

// Collapsing: decided by the open class, which changes at once, as
// isExpanded only changes once the animation's finished (so is out of
// date for a toggle made while the panel's still opening or closing).
if (!this.$element.hasClass("open")) {

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.

You've eliminated the vast majority of references to this.isExpanded. Is it possible/should we fully eliminate the property? (It probably is best to leave it as-is for release 2.5, but maybe more cleanup can be done in 3.0 -- if this is a good idea, maybe we should track it with an issue; I haven't investigated whether this is already changed by the UI work in progress).

This branch was successfully deployed

2 active deployments
Preview – universalviewer — 22cc50f1 Deployed Nov 23, 2026 by vercel[bot]
Preview – universalviewer.dev — 22cc50f1 Deployed Nov 23, 2026 by vercel[bot]
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