Media Player

Your video or audio, with controls as parts that fit the player's width — its state two ways, captions, chapters, keyboard shortcuts and the system's media controls.

MediaExperimental

Usage

Usage

import { Component, ViewEncapsulation } from '@angular/core';import {  ScMediaPlayer,  ScMediaPlayerCaptions,  ScMediaPlayerCaptionsDisplay,  ScMediaPlayerControls,  ScMediaPlayerFullscreen,  ScMediaPlayerLoop,  ScMediaPlayerMedia,  ScMediaPlayerMute,

Anatomy

The player, your media, and the controls you want — in one row that wraps. Everything else (a spinner, an error, the length before the first play, a spacer) is your markup, from the player's state.

import { ScMediaPlayer, ScMediaPlayerCaptions, ScMediaPlayerCaptionsDisplay, ScMediaPlayerControls, ScMediaPlayerFullscreen, ScMediaPlayerLoop, ScMediaPlayerMedia, ScMediaPlayerMute, ScMediaPlayerPictureInPicture, ScMediaPlayerPlay, ScMediaPlayerPreview, ScMediaPlayerRate, ScMediaPlayerSeek, ScMediaPlayerSkip, ScMediaPlayerTime, ScMediaPlayerVolume, ScMediaPlayerWaveform } from '@semantic-components/ui';
<div scMediaPlayer #player="scMediaPlayer" aria-label="Video: Sintel">  <video scMediaPlayerMedia src="…" poster="…"><track kind="captions" … /></video>  <div scMediaPlayerCaptionsDisplay></div>  <button scMediaPlayerPlay>…</button>  <div scMediaPlayerControls>    <input scMediaPlayerSeek aria-label="Seek" />    <div scMediaPlayerPreview>…</div>    <button scMediaPlayerPlay>…</button>    <button [scMediaPlayerSkip]="-10">…</button>    <button scMediaPlayerMute>…</button>    <input scMediaPlayerVolume aria-label="Volume" />    <time scMediaPlayerTime></time> / <time scMediaPlayerTime="duration"></time>    <button [scMediaPlayerRate]="1.5">1.5×</button>    <button scMediaPlayerLoop>…</button>    <button scMediaPlayerCaptions>…</button>    <button scMediaPlayerPictureInPicture>…</button>    <button scMediaPlayerFullscreen>…</button>  </div></div>

Small players

The player is a container (@container/media), and its parts fit themselves to its width — the template stays the same, and no script measures it (the server's render is right). Under 672px (an audio bar: 448px) the speeds and loop step aside; under 576px (384px), the small layout:

  • A play outside the controls sits in the middle, and the controls' play steps aside. Wide, the middle play shows only while paused.
  • The seek bar goes to the bottom edge; the skips, picture-in-picture, the volume and (over a video) mute step aside too. The time, captions and fullscreen stay.
  • With a play in the middle, the controls wait for the first play: the poster, its play and your length show first.

Keyboard

Focused in the player (never page-wide):

KeyDoes
Space / KPlay / pause
J / L10 seconds back / forward
← / →5 seconds back / forward
↑ / ↓Volume up / down
MMute
RLoop
< / >Slower / faster
CCaptions
FFullscreen
PPicture in picture
0 / 9Jump to that tenth (0 to 9)
Home / EndThe start / the end

Fields keep their keys; buttons keep Space and Enter. On the seek bar, the arrows move five seconds.

Accessibility

  • Name the player (aria-label), every button (visually hidden text) and the sliders. The seek bar reads its time ("0:15"); add your words in aria-valuetext.
  • Toggles (mute, loop, captions, a speed, fullscreen, picture-in-picture) are aria-pressed.
  • Captions are shown by the player, in a polite live region above the controls; the browser's own are off.
  • The controls hide only while a video plays untouched — never while focused in them, or paused. On a touch screen, once played, a tap on the video shows or hides them; a mouse click plays or pauses.

Examples

Responsive

Drag the box's corner to resize it.

import { Component, ViewEncapsulation } from '@angular/core';import {  ScMediaPlayer,  ScMediaPlayerCaptions,  ScMediaPlayerCaptionsDisplay,  ScMediaPlayerControls,  ScMediaPlayerFullscreen,  ScMediaPlayerLoop,  ScMediaPlayerMedia,  ScMediaPlayerMute,

Minimal

import { Component, ViewEncapsulation } from '@angular/core';import {  ScMediaPlayer,  ScMediaPlayerControls,  ScMediaPlayerFullscreen,  ScMediaPlayerMedia,  ScMediaPlayerPlay,  ScMediaPlayerSeek,  ScMediaPlayerTime,} from '@semantic-components/ui';

Captions

Captions:
import { Component, ViewEncapsulation, computed, signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';import {  ScField,  ScMediaPlayer,  ScMediaPlayerCaptions,  ScMediaPlayerCaptionsDisplay,  ScMediaPlayerControls,  ScMediaPlayerMedia,  ScMediaPlayerPlay,

Controlled

00:00 — paused

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScButton,  ScMediaPlayer,  ScMediaPlayerMedia,} from '@semantic-components/ui';
/** State two ways: [(paused)] and [(currentTime)] from outside — a play button and the chapters, read from the video. */@Component({  selector: 'app-controlled-media-player-demo',

Audio

Carefree

Kevin MacLeod

import { NgOptimizedImage } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import {  ScMediaPlayer,  ScMediaPlayerControls,  ScMediaPlayerLoop,  ScMediaPlayerMedia,  ScMediaPlayerMute,  ScMediaPlayerPlay,  ScMediaPlayerSeek,

Error

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScButton,  ScMediaPlayer,  ScMediaPlayerControls,  ScMediaPlayerMedia,  ScMediaPlayerPlay,  ScMediaPlayerSeek,  ScMediaPlayerTime,} from '@semantic-components/ui';

RTL

import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import {  ScMediaPlayer,  ScMediaPlayerCaptions,  ScMediaPlayerCaptionsDisplay,  ScMediaPlayerControls,  ScMediaPlayerFullscreen,  ScMediaPlayerLoop,  ScMediaPlayerMedia,

API reference

Each part takes class, merged over its own (cn: a later class wins). The buttons are the style's (variant, size: ghost, icon-sm); over a video, white. The frame, an audio card, the controls' padding and the preview's corners are the style's (mediaPlayer), after its Card and Tooltip.

PartSelectorDescription
ScMediaPlayer[scMediaPlayer] The state (two-way and read), the keys, a container. exportAs: toggle(), seekTo(), seekBy(), volumeBy(), rateBy(), toggleCaptions(), toggleFullscreen(), togglePictureInPicture(), reload(), formatTime(), chapterAt().
ScMediaPlayerMediavideo[scMediaPlayerMedia], audio[scMediaPlayerMedia] Your media element, with its sources and tracks.
ScMediaPlayerControls[scMediaPlayerControls] A row that wraps; over a video, hides while it plays untouched.
ScMediaPlayerPlaybutton[scMediaPlayerPlay] Play, pause, replay; outside the controls: in the middle.
ScMediaPlayerSkipbutton[scMediaPlayerSkip] Jumps by its seconds (negative: back).
ScMediaPlayerSeekinput[scMediaPlayerSeek] The time, as a slider: loaded and chapters on its track.
ScMediaPlayerWaveformdiv[scMediaPlayerWaveform] The media as bars, read from its file: a seek bar for audio (bars input). See the Playlist recipe.
ScMediaPlayerPreview[scMediaPlayerPreview] Your text above the seek bar, where the pointer is.
ScMediaPlayerMute / Volumebutton[scMediaPlayerMute], input[scMediaPlayerVolume] Mute, and the volume as a slider.
ScMediaPlayerTimetime[scMediaPlayerTime] current (default), duration or remaining.
ScMediaPlayerRatebutton[scMediaPlayerRate] A speed, pressed while it plays at it.
ScMediaPlayerLoop / Captionsbutton[scMediaPlayerLoop], button[scMediaPlayerCaptions] Loop; captions on and off.
ScMediaPlayerCaptionsDisplaydiv[scMediaPlayerCaptionsDisplay] The captions, over the video.
ScMediaPlayerPictureInPicture / Fullscreenbutton[scMediaPlayerPictureInPicture], button[scMediaPlayerFullscreen] A window of its own; full screen (video only).
InputTypeDefaultDescription
paused, currentTime, volume, muted, playbackRate, loopboolean | numbertrue, 0, 1, false, 1, false Two-way.
captionsstring | nullnull Two-way: the captions shown, a track’s id.
metadataMediaMetadataInit— For the system’s media controls.