Home

Awesome

MSE (Media Source Extensions) Audio Wrapper

mse-audio-wrapper is a library to enable Media Source Extensions API playback for unsupported audio containers and raw codecs. MSE Audio Wrapper uses both WEBM and the ISO Base Media File Format (MPEG-4 Part 12) (commonly referred to as Fragmented MP4 or fmp4).


Installing

Install via NPM

Usage

  1. To use MSEAudioWrapper, create a new instance of the class by passing in the mimetype of your audio data.

    Note: For directly converting from a HTTP response, use the mimetype contained in the Content-Type header

    import MSEAudioWrapper from "mse-audio-wrapper";
    
    const headers = myHTTPResponse.headers;
    const mimeType = headers.get('Content-Type');
    
    const audioWrapper = new MSEAudioWrapper(mimeType);
    
  2. To begin processing audio data, pass in the audio data into the instance's .iterator(). This method returns an iterator that can be consumed using a for ...of or for await...of loop. Repeat this step until all audio data has been read.

    const audioData = response.body;
    
    for (const wrappedAudio of audioWrapper.iterator(audioData)) {
      // Do something with the wrapped data
    }
    

API

MSEAudioWrapper

Default export

const wrapper = new MSEAudioWrapper("audio/mpeg", {minFramesPerSegment: 2, minBytesPerSegment: 576, preferredContainer: "webm"});

getWrappedMimeType(codec, container = WEBM)

Named export

Returns the mime-type that MSEAudioWrapper will produce given a passed in codec and container type.


Demo

mse-audio-wrapper is used in the demo for icecast-metadata-js to allow for Icecast metadata support in Firefox (mp3, aac, flac) and Chrome (flac) by wrapping the streaming audio in ISOBMFF so it can be used with the MediaSource API.

https://github.com/eshaz/icecast-metadata-js/tree/master/src/demo

View the live demo here: https://eshaz.github.io/icecast-metadata-js/