Overview of Media Chrome
<video> and <audio> elements, as well as any element conforming to the HTMLMediaElement API. It works across various frameworks including React, Angular, VueJS, and Svelte.website·Indexed 35 days ago
https://www.media-chrome.orgA library of customizable Web Components for building media player interfaces. It includes a comprehensive set of UI components like <media-controller>, <media-control-bar>, and <media-volume-range>, as well as support for React via specialized hooks and <MediaProvider>. The documentation covers theme creation, responsive controls, CSS variable styling, and integration with various media elements such as <dash-video>, <vimeo-video>, and <cloudflare-video>.
<video> and <audio> elements, as well as any element conforming to the HTMLMediaElement API. It works across various frameworks including React, Angular, VueJS, and Svelte.<media-controller> element acts as the orchestrator for a media player, managing the communication of state and state change requests between a media element and its associated control elements. It also provides built-in sizing and layout to simplify player styling.Media Chrome is built on several core architectural goals to ensure developer flexibility:
<button> works independently of a <form>.<media-mute-button> component toggles the sound of the media. It automatically updates its displayed content based on the current audio volume level: 'off' (muted/0%), 'low' (0-50%), 'medium' (50-75%), and 'high' (75-100%).<media-controller>
<video slot="media" src="video.mp4"></video>
<media-control-bar>
<media-mute-button></media-mute-button>
<media-volume-range></media-volume-range>
</media-control-bar>
</media-controller><media-pip-button> component provides a toggle for a video's picture-in-picture (PiP) mode. It automatically updates its displayed content based on whether the media is currently in PiP mode and whether the browser supports the feature.<media-controller defaultsubtitles>
<video
playsinline muted crossorigin
slot="media"
src="https://stream.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/low.mp4"
></video>
<media-pip-button></media-pip-button>
</media-controller>MediaStore state management API. This allows developers to build custom React components that can read media state and request state changes. All necessary tools are exported from the media-chrome/react/media-store module.import {
MediaProvider,
useMediaDispatch,
useMediaSelector,
useMediaRef,
useMediaFullscreenRef,
MediaActionTypes,
} from 'media-chrome/react/media-store';Key additions in v1.0 include:
<media-controller> now dispatches a breakpointchange event.mediaended state attribute applied to <media-play-button>.icon slot for all components with customizable icons.Media Chrome uses a centralized controller architecture to handle interactions and state:
<media-controller> element.<media-controller> catches these events and calls the appropriate API on a child media element (such as <video> or <audio>) that is designated with the attribute slot="media".<media-ui-element mediapaused>).<media-controller>, the controller updates these attributes automatically.mediacontroller="" attribute or a JavaScript function.<media-controller>
<!-- The media element being controlled -->
<video slot="media" src="video.mp4"></video>
<!-- UI elements that emit events and receive state attributes -->
<media-play-button></media-play-button>
</media-controller><media-captions-button> component is used to toggle captions and subtitles on and off. It prefers captions tracks over subtitles tracks when enabling. The button's state is driven by the text track media state: it displays the on slot when any captions/subtitles are enabled, and the off slot when all are disabled.<media-controller defaultsubtitles>
<video
playsinline muted crossorigin
slot="media"
src="https://stream.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/low.mp4"
>
<track label="English" kind="captions" srclang="en" src='https://media-chrome.mux.dev/examples/vanilla/vtt/en-cc.vtt' />
</video>
<media-captions-button></media-captions-button>
</media-controller>The <media-control-bar> container component provides automatic layout capabilities when used within a <media-controller>:
<media-time-range> automatically expand to fill available space.<media-time-display> component shows the current or remaining time of media playback. By default, it displays the elapsed time. Users can click the component to toggle between showing the current time and the remaining time.<media-controller>
<video
slot="media"
src="https://stream.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/low.mp4"
playsinline
muted
>
</video>
<media-control-bar>
<media-play-button></media-play-button>
<media-time-display></media-time-display>
</media-control-bar>
</media-controller>slot attribute to identify which state the icon represents (e.g., slot="play" or slot="pause"). You can use SVGs, images, or font icons.<media-play-button>
<svg slot="play" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="..."/>
</svg>
<svg slot="pause" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="..."/>
</svg>
</media-play-button>