Playlist

A recipe: songs one after another, on a Media Player — its waveform, next and previous, shuffle and repeat, the list to choose from. No component of its own.

Usage

Usage

Carefree

Kevin MacLeod

import { NgOptimizedImage } from '@angular/common';import {  Component,  DestroyRef,  ViewEncapsulation,  afterNextRender,  computed,  inject,  signal,  viewChild,

How it is made

The player plays the file you give it: the songs, the one playing (a signal of yours), shuffle and repeat are your state. The <audio> takes the song's src; its (ended) moves on. Another song chosen while one plays plays at once (the audio's autoplay, set as you change it).

  • Next: the following song in the order — after the last, the first with repeat all, or it stops. Previous: the song's start, or within three seconds of it, the one before.
  • Repeat one is the player's loop (its R key too); shuffle, an order made once, every song in it once, the one playing first.
  • The waveform (scMediaPlayerWaveform) is the seek bar; the list is Items (button[scItem]), the one playing aria-current. The system's media controls get next and previous from you (navigator.mediaSession).
import { ScItem, ScMediaPlayer, ScMediaPlayerMedia, ScMediaPlayerPlay, ScMediaPlayerTime, ScMediaPlayerWaveform, ScToggle } from '@semantic-components/ui';
<div scMediaPlayer #player="scMediaPlayer" aria-label="Player" [loop]="repeat() === 'one'">  <audio scMediaPlayerMedia [autoplay]="autoplay()" [src]="song().src" (ended)="next()"></audio>  <div scMediaPlayerWaveform aria-label="Seek"></div>  <time scMediaPlayerTime></time> <time scMediaPlayerTime="remaining"></time>  <button scToggle [(pressed)]="shuffle">…</button>  <button scButton (click)="previous()">…</button>  <button scMediaPlayerPlay>…</button>  <button scButton (click)="next()">…</button>  <div scItemGroup role="list" aria-label="Playlist">    <div role="listitem"><button scItem (click)="choose(i)">…</button></div>  </div></div>

Accessibility

  • Name the player and every button. Shuffle is a toggle (a fixed name, pressed); repeat has three states, so its name says which ("Repeat: all"), never pressed.
  • The waveform is a slider reading the time ("0:15"); the song playing is aria-current in the named list.
  • Focused in the player, its keys work: Space plays, R repeats the song.

Examples

RTL

Carefree

Kevin MacLeod

import { Dir } from '@angular/cdk/bidi';import { NgOptimizedImage } from '@angular/common';import {  Component,  DestroyRef,  LOCALE_ID,  ViewEncapsulation,  afterNextRender,  computed,  inject,