UNPKG

@firstcoders/hls-web-audio

Version:

`@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.

34 lines (31 loc) 759 B
/** * Loads raw segment bytes and supports aborting in-flight network requests. */ export default class SegmentLoader { constructor() { this.abortController = new AbortController(); } /** * Fetches segment bytes from the network. * * @param {string} src * @param {RequestInit} [fetchOptions={}] * @returns {Promise<ArrayBuffer>} */ async load(src, fetchOptions = {}) { const response = await fetch(src, { signal: this.abortController.signal, ...fetchOptions, }); if (!response.ok) { throw new Error(`Fetch failed with status ${response.status}`); } return response.arrayBuffer(); } /** * Aborts the active fetch request. */ cancel() { this.abortController.abort(); } }