npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@firstcoders/hls-web-audio

v3.0.0-beta.1

Published

`@firstcoders/hls-web-audio` plays multiple streamed audio tracks in sync using the Web Audio API. It is designed for stem-like playback where each track can be independently loaded, buffered, scheduled, and mixed.

Readme

hls-web-audio

@firstcoders/hls-web-audio plays multiple streamed audio tracks in sync using the Web Audio API. It is designed for stem-like playback where each track can be independently loaded, buffered, scheduled, and mixed.

The package supports HLS manifests (.m3u8) and browser-supported audio formats.

Install

npm i @firstcoders/hls-web-audio

Public API

import { Controller, HLS } from '@firstcoders/hls-web-audio';

Also exported as subpaths:

  • @firstcoders/hls-web-audio/core/AudioController.js
  • @firstcoders/hls-web-audio/track/HLS.js

Quick Start

import { Controller, HLS } from '@firstcoders/hls-web-audio';

const controller = new Controller({ loop: false });

const drums = new HLS({ controller });
const bass = new HLS({ controller });
const vocal = new HLS({ controller });

await Promise.all([
  drums.load('https://example.com/drums.m3u8').promise,
  bass.load('https://example.com/bass.m3u8').promise,
  vocal.load('https://example.com/vocal.m3u8').promise,
]);

await controller.play();

// seek by absolute time or percentage
controller.currentTime = 30;
controller.pct = 0.5;

Architecture

The runtime is split into clear layers:

  • src/core/: global playback orchestration
  • src/track/: per-track scheduling and segment ordering
  • src/io/: manifest loading, segment loading, decoding, and connection
  • src/lib/: helper utilities

Core Layer (src/core)

  • AudioController: top-level facade and event hub
  • PlaybackEngine: handles play/pause state and buffering transitions
  • PlaybackTimeline: computes currentTime, seek offsets, and percentages
  • Timeframe: immutable-ish snapshot used for scheduling calculations
  • TrackGroup: maintains track collection and aggregate readiness
  • Observer: event emitter primitive used by the controller

Track Layer (src/track)

  • Track: base track behavior and controller wiring
  • HLS: HLS-specific track that builds segments from manifests
  • TrackScheduler: lookahead scheduler for loading/connecting segments
  • Stack: doubly linked list that stores segments in timeline order

I/O Layer (src/io)

  • ManifestLoader: fetches/parses manifests
  • AudioSegment: segment model and lifecycle
  • SegmentLoader: network fetch for segment bytes
  • SegmentBuffer: decode/cache management
  • SegmentPlayer: source-node connection/disconnection behavior

Playback Flow

  1. HLS.load() fetches and parses the manifest.
  2. Segment objects are created and pushed into Stack (linked list).
  3. TrackScheduler.runSchedulePass() picks upcoming segments in a lookahead window.
  4. Each segment is loaded (if needed), decoded, and connected at precisely calculated start/offset times via Timeframe.
  5. PlaybackEngine monitors readiness (shouldAndCanPlay) and suspends/resumes audio context during buffering.
  6. The UI reads controller.currentTime / controller.pct and renders progress.

Linked-List Segment Stack

Stack uses a doubly linked list (head, tail, prev, next) instead of an array.

Why this matters:

  • Efficient local traversal around current playback position using #lastAccessed cache.
  • Stable neighbor access for lookbehind/lookahead operations.
  • Low-overhead start-time recomputation from a changed node onward via recalculateStartTimes(fromSegment).
  • Natural support for scheduler operations that move forward/backward through nearby segments repeatedly.

Scheduling and Buffering Model

All scheduling computation happens at precomputed, event-driven moments — not on a fixed polling interval. TrackScheduler runs a lookahead pass, connects upcoming segments into the Web Audio graph, then sleeps until a calculated boundary is reached.

PlaybackEngine monitors playhead readiness and drives buffering transitions; it does not render frames or tick at a fixed rate.

See docs/scheduling.md for a detailed description of:

  • the time anchor (adjustedStart) and why currentTime is a pure read
  • when and how often runSchedulePass fires
  • the #scheduleNotBefore lookahead boundary and its self-timer
  • the recovery heartbeat for aborted schedule paths
  • seek / region-change coordination with disconnectAll
  • the full buffering lifecycle

Events

Common controller events:

  • start
  • pause
  • pause-start
  • pause-end
  • seek
  • end
  • duration
  • offset
  • playDuration
  • error
  • init

Example:

controller.on('start', () => {});
controller.on('pause-start', () => {});
controller.on('pause-end', () => {});
controller.on('seek', ({ t, pct, remaining }) => {});
controller.on('error', (err) => console.error(err));

UI Time Updates

This package no longer owns a high-frequency UI timeupdate loop. The intended model is:

  • audio readiness, scheduling, and buffering are handled in @firstcoders/hls-web-audio
  • visual clock/progress rendering is handled by the consumer UI layer

Typical UI pattern:

function renderTick() {
  const t = controller.currentTime;
  const pct = controller.pct;
  // update UI
  requestAnimationFrame(renderTick);
}
requestAnimationFrame(renderTick);

Contributing

This repo is a subtree split of our monorepo which will be made public in due course. We cannot process pull requests to this repo. Please contact us for support.