Skip to main content

Loading a sound

In order to play a sound your clip should first load it. Sounds are part of the context and they can be loaded by just passing them on the audioSources key of your Clip’s properties. E.g.

const MyClip = new HTMLClip({
html: `....`,
css: `....`,
audioSources: [
{
src: "./link/to/your.mp3",
id: "an-id-must-be-unique",
classes: ["class1", "class2", "class3"],
base64: false,
startValues: {
pan: -1,
gain: 0,
},
},
{
src: "T2dnUwACAAAAAAAAAAA+HAAAAAAAAGyawCEBQGZpc2hlYWQAAwA...",
id: "an-id-must-be-unique",
classes: ["class1", "class2", "class3"],
base64: true,
},
],
});

Each audioSource can be either base64 or just a file of the supported by web Audio API formats (mp3, wav, ogg, etc). In the case the sound is base64 you provide it on the src and you should set the “base64” flag to true, while in the case of a file sound you just pass the url of the file on the src and you should set the “base64” flag to false.

For each audio you can set its id on the “id” key and you can also define a list of classes this audio belongs to via the (optional) “classes” key. Both the id and the classes can be used via the audio Incidents as selectors.

Finally the startValues define the start / default gain (volume) and pan (stereo pan) of the audioSource.