@asset-manager/audio
v0.0.3
Published
A singleton for loading and retrieving audio assets used in your application.
Downloads
4
Maintainers
Readme
@asset-manager/audio
This package provides loaders for preloading audio type assets.
Introduction
This package contains two loaders that return either an audio buffer or base64 string that can be used as a source for the audio library of choice.
Loading and retrieving assets.
import AssetManager from "@asset-manager/core";
import { AudioBufferLoader, AudioBase64Loader } from "@asset-manager/audio";
// Get an instance to the manager and set the loaders
const manager = AssetManager.getInstance();
manager.setLoaders({
audioBuffer: AudioBufferLoader,
audioBase64: AudioBase64Loader,
});
// Set the assets to load
manager.setAssets([
{
id: "bufferName",
url: "static/audio/audioFile.m4a",
type: "audioBuffer",
preload: true,
params: {
audioContext: audio.audioContext,
},
},
{
id: "base64Name",
url: "static/audio/audioFile.m4a",
type: "audioBase64",
preload: true,
},
]);
// Elsewhere in your app you can grab assets from the manager
const buffer =
AssetManager.getInstance().get<AudioBufferLoader>("bufferName").audioBuffer;
const base64String =
AssetManager.getInstance().get<AudioBase64Loader>("base64Name").audioBase64;
Installation
Install this package with npm
.
npm i @asset-manager/audio
This package does not include the core loader. You will need to install that separately
npm i @asset-manager/core