$ npm install @koodu-platform/resonance
const soundOptions ={
baseURL: 'fixtures/',
audioPaths: ['./whoosh.mp3']
}
const mySound = new resonance.sound(soundOptions);
const playButton = document.getElementById('btn');
playButton.addEventListener('click', async (ev) => {
try {
await mySound.play(1);
} catch (error) {
console.error('Error playing sound:', error.message);
}
});
Creates a new instance of the Resonance sound, which is a simple DOM event-driven sound abstraction library.
-
options
: An object that contains the following properties:-
baseURL
: The base URL for the audio file paths. -
audioPaths
: An array or string of audio file paths. -
searchParams
: Optional search parameters for audio file URLs.
-
Loads the audio files.
-
filePaths
: An array or string of file paths to the audio files.
Plays the loaded audio.
-
volume
: The volume level (default is 1).
Resumes playing from a specified time.
-
resumeTime
: The time to resume from.
Pauses the currently playing audio.
Stops the currently playing audio.
Disposes of the sound instance.
Loads and plays the previously loaded sound.
Loads and plays the next loaded sound.
SOUND_CREATED
SOUND_PAUSED
SOUND_PLAYING
SOUND_RESUMED
SOUND_STOPPED
SOUND_LOADING
SOUND_LOADED
SOUND_ERROR