Video Player Overhaul: Media Chrome Native Controls
Replace custom popover, chapter list, and marker systems with media-chrome’s built-in components. Vendor the menu module. Delete ~170 lines of custom CSS and significant JS. Keep annotation markers and margin-box systems.
Motivation
The current video player uses media-chrome for play/scrub/fullscreen but builds its own settings popover, chapter list, and marker system out of raw DOM. This produces:
- Ugly, poorly-spaced settings popup that doesn’t fit its content
- Chapters crammed into the settings menu instead of a proper submenu
- No mute button
- Time display that doesn’t shrink on narrow viewports
- Annotation/chapter markers that don’t rescale on fullscreen
- Play/fullscreen icons that render poorly on mobile
- Oversized Unicode gear icon (⚙) instead of a proper SVG
Most of these are solved by leaning harder into media-chrome rather than fighting it.
What media-chrome already provides
| Problem | media-chrome solution | In our bundle? |
|---|---|---|
| Ugly settings popup | <media-settings-menu> with animated submenus |
Needs menu/ module |
| Chapters crammed in | Built-in chapter segments in <media-time-range> from <track kind="chapters"> |
✅ Yes |
| No mute button | <media-mute-button> with volume level icons |
✅ Yes |
| Time display too wide | CSS custom properties for sizing | ✅ Yes |
| Markers don’t rescale | Built-in segments auto-resize on fullscreen | ✅ Yes |
| Bad mobile icons | CSS --media-button-icon-width/height |
✅ Yes |
| Oversized gear | <media-settings-menu-button> with proper ⋯ SVG |
Needs menu/ module |
Vendoring
Two files, loaded only on pages with video figures:
assets/js/vendor/media-chrome.esm.js— existing (179KB)assets/js/vendor/media-chrome-menu.esm.js— new (~81KB)
Source: https://cdn.jsdelivr.net/npm/media-chrome@4/menu/+esm
The menu bundle re-registers some shared base classes but
customElements.define() guards prevent double-registration.
Control Bar Layout
[Play] [Mute] [0:32 / 10:53] [==☞=|====|=====☞==|===] [⋯] [Fullscreen]
^ ^ ^
chapter segments (built-in)
☞ = annotation manicule markers
Components left to right:
<media-play-button>— play/pause toggle<media-mute-button>— mute/unmute with volume level icons<media-time-display showduration>— current / duration<media-time-range>— scrub bar with automatic chapter segments<media-settings-menu-button>— opens settings menu (⋯ icon)<media-fullscreen-button>— fullscreen toggle
Settings Menu Structure
⋯ (three-dot button)
├── Quality → [Original (360p) ✓] [Enhanced (360p)] [Enhanced (Full) — 409MB]
└── Annotations → [On ✓] [Off]
Quality: Dynamic <media-chrome-menu> with radio items inside a
<media-settings-menu-item slot="submenu">. Built from
<source data-label> elements. Same switching logic as today
(capture currentTime, swap video.src, restore on
loadedmetadata).
Annotations: <media-chrome-menu-item type="checkbox"> toggle.
Same localStorage persistence.
Chapters removed from settings. They have three representations
already: margin box TOC (via video-scenes.js), built-in chapter
segments in the scrub bar, and chapter name in hover preview. A
fourth copy in a popover is clutter.
Annotation Manicule Markers
Custom annotation markers stay on the scrub bar — media-chrome doesn’t know about our metadata VTT cues. But redesigned:
Current: 4px square <div> blobs, positioned once, don’t
rescale on fullscreen.
New: Tiny SVG manicule (☞) silhouettes, ~6–8px, positioned as
percentage offsets along the track. Use a ResizeObserver on the
<media-time-range> to realign on fullscreen and resize. The
pointing-hand motif matches the sidenote manicules — Almanack’s
visual signature carried into the timeline.
Implementation: SVG <use> elements referencing a single <symbol>
definition, or inline SVG paths in a container overlaid on the time
range with pointer-events: none.
What We Delete
CSS (~170 lines)
.vf-settings-wrap,.vf-settings-btn,.vf-settings-popover.vf-settings-heading,.vf-settings-row.vf-quality-list,.vf-quality-item,.vf-quality-active.vf-annotation-toggle.vf-chapter-list,.vf-chapter-item,.vf-chapter-time,.vf-chapter-name,.vf-chapter-active.vf-chapter-label.chapter-markers,.chapter-marker.vf-time-range-wrap(simplified — markers overlay directly)
JS
- Custom popover system in
video-player.js: gear button, popover div, click-outside handler, Escape handler, quality list builder, annotation toggle builder, chapter label overlay buildChapterMenu()invideo-scenes.js(margin TOC stays)renderChapterMarkers()invideo-player.jsalignMarkersToTrack()/getTrackBounds()helpers
What Stays Ours
- Annotation marker rendering — custom VTT metadata cues, redesigned as manicule SVGs with ResizeObserver for fullscreen
- Quality switching logic —
video.srcswap withcurrentTimerestore, rewired to menu item clicks - Annotation toggle — same localStorage logic, rendered as
<media-chrome-menu-item> - SVG overlay shapes and connectors — untouched
- Margin annotations (
video-annotations.js) — untouched - Margin chapter TOC (
video-scenes.js) — untouched minus the settings menu chapter list - VTT parsing (
vtt.js) — untouched - Time fragment handling (
#t=) — untouched - Figures runtime (
runtime.js) — untouched
CSS Theming (Light Touch)
media-controller {
--media-primary-color: #fff;
--media-secondary-color: rgb(20 20 30 / .7);
--media-font: var(--font-body);
--media-font-size: 0.8rem;
--media-icon-color: #fff;
--media-button-icon-width: 20px;
--media-button-icon-height: 20px;
--media-range-track-border-radius: 0;
--media-range-thumb-border-radius: 0;
--media-range-segments-gap: 2px;
}
media-time-display {
font-family: var(--font-mono);
font-variant-numeric: tabular-nums;
font-size: 0.75em;
}
media-settings-menu {
--media-menu-background: rgb(20 20 30 / .9);
--media-font: var(--font-body);
border-radius: 2px;
}
Sharp corners, body font for menus, mono for timecodes, white on dark. No custom borders, no elaborate wash. Let media-chrome handle layout and interaction; we handle palette.
Progressive Degradation
| Feature | Without JS | media-chrome fails | Everything loads |
|---|---|---|---|
| Playback | Native <video controls> |
Native <video controls> |
media-chrome player |
| Chapters | Browser renders natively | Browser renders natively | Segments in scrub bar + margin TOC |
| Settings | No | No | ⋯ menu with quality + annotations |
| Volume | Hardware buttons | Hardware buttons | <media-mute-button> |
| Annotations | No | No | Margin boxes / overlay |
| Keyboard | Browser defaults | Browser defaults | media-chrome hotkeys |
Files Changed
New
assets/js/vendor/media-chrome-menu.esm.js— vendored menu bundle
Modified
assets/js/figures/video-player.js— major rewrite of control bar construction and settings popoverassets/js/figures/video-scenes.js— removebuildChapterMenu(), keep margin TOCassets/css/almanack.css— delete custom popover/chapter CSS, simplify media-chrome theme
Unchanged
assets/js/figures/video-annotations.jsassets/js/figures/vtt.jsassets/js/figures/runtime.jsassets/js/vendor/media-chrome.esm.js- Article markdown (no changes to editorial content)
Testing
- Existing mobile tests continue to pass (video player is on Kropotkin article, tested via Playwright)
- Visual inspection: desktop wide, desktop narrow, iOS Simulator
- Verify: play/pause, mute, scrub with chapter segments, settings
menu opens with quality + annotations, fullscreen with rescaled
markers,
#t=fragment seek, margin annotations, annotation toggle persistence