SonicFrame v1.3.2

Now playing

A small bar fixed to the window that follows the player that started playing last, any player of the page, so the sound can be controlled while the page scrolls.

Try it

Play the sound, then scroll the player out of view: the bar comes up at the bottom of the window.

Adding it

import { nowPlaying } from 'sonicframe/playlist';

nowPlaying({ parts: ['play', 'title', 'time', 'progress', 'back', 'close'] });

One bar serves every player of the page, made with createPlayer, the tag or a playlist. A playlist can bring its own with nowPlaying: true (or the now-playing attribute), and currentPlayer() in sonicframe/player gives the player that played last.

Options

Option Default What it does
when 'outOfView' 'outOfView' (playing and out of view), 'playing' or 'always' (from the first play on, paused too).
place 'bottom' 'bottom' or 'top' of the window, clear of a phone's rounded edges.
align 'stretch' 'stretch', 'start', 'center' or 'end'.
offset 0.5 Space from the window's edge, in rem, from 0 to 20: room for your own fixed footer.
width 28 Its width when it does not stretch, in rem, from 10 to 60.
zIndex 2147483640 Its stacking order.
parts play, title, time, progress, close What it holds, in order; also previousTrack, nextTrack, back (scrolls to the player and gives it the focus) and speed.
palette 'player' The colors of the player playing, or a palette of its own; font and box as for the chapters' list.
close 'untilNextPlay' Closed, it stays away until the next play, or 'forPage'.
animation false Moves in as it shows (animationType: 'slide' or 'fade'), never for people who asked for less motion.
a11y label ("Now playing"), announce (off), lang and words.

On the tag

<sonic-now-playing parts="play title time back close" place="bottom"></sonic-now-playing>

<script type="module">
    import { defineSonicNowPlaying } from 'sonicframe/playlist';
    defineSonicNowPlaying();
</script>

The attributes are those of the options: when, place, align, offset, width, z-index, parts, palette, font, close, animation, animation-type and the a11y- ones.

For screen readers and the keyboard

  • The bar is a region named "Now playing"; it never takes the focus when it shows.
  • Every part is a real button with a name; play says "Play" or "Pause", and the time is text.
  • Escape closes it while the focus is in it.
  • a11y.announce says the sound's name when it shows. Off by default.