Introduction
musquito is an audio engine created using Web Audio API for HTML5 games and interactive websites. It provides a simple abstraction to create and play sounds easier.
Below are some of the core features supported by the library.
- Built on the powerful Web Audio API
- Simple API to create and play sounds
- Supports sound groups
- Supports variety of codecs
- Supports audio sprites
- Supports streaming using HTML5 audio nodes
- Fading
- Caching
- Auto Garbage Management
Browser Support
- Google Chrome
- Firefox
- Safari
- Opera
- Microsoft Edge
Installation
At this time musquito is available only in npm and you can install it using the below command.
npm install musquito --save
Listing 1. Installing musquito using npm
You can also directly reference files available from the distribution folder.
<script src="musquito/dist/musquito.min.js"></script>
Listing 2. Referencing musquito file using script tag
"Hello World" Example
A simple example of how to create and play a gun fire sound.
Passing Additional Parameters
The below example shows how you can pass additional parameters like volume, rate and callback.
Using Sprites
Audio Sprites are like image sprites concatenates multiple small sounds in a single file. You can create audio sprite using this tool.
Below is an example of how to use sprites.
Pausing and Stopping Sounds
Calling the
play method returns the sound id and you can use it to call other methods like pause, stop, change the volume and more properties of the sound.Fading Sounds
You can fade the volume of a playing sound linearly or exponentially as shown below.
Streaming
Long audio files can be played using HTML5 audio nodes by passing
stream option as true.Advanced Example
The below example shows how we can setup audio engine by passing audio resources with shorthand identifiers initially before playing sounds. The
setup method also takes lot of other arguments to configure the engine, please refer the API docs.Creating Audio Groups
Sometimes it's convenient to create a sound group which is called as "Buzz" that helps to create and manage multiple sounds for a single audio resource. Buzzes also supports events. The below example shows how we can create a sound group for a sprite and play multiple sounds easier.
No comments:
Post a Comment