Sound Basics

Playing

Creation of a sound is simple. Normally play returns the SoundInstance, but in this case it does not because the sound is not preloaded.

To start playing the sound immediately after load is finished use the autoPlay flag.

Globally, you can also use the PIXI.sound library methods (add, play) for adding and playing a sound as well.

You can set options when playing a sound

You can also set filters for different instances, in this demo you will hear two birds sounds, one is the left, one on the right.

Filetypes

Not all web-browsers support different file extensions for audio playback. Setup fallback formats easily by useing the a glob-like expression for the file extension. This will prioritize format from left to right.

Alternatively, if you don't plan to use Assets (typically because you're using a bundler like Parcel or Webpack), but you still would like to resolve multiple files, you can choose from multiple URLs.

Preloading

Preloading a sound can be enabled by passing in the preload flag. You can listen for when the sound is loaded by using the loaded callback.

PIXI's loader can be used to load Sound assets. This returns the Sound object on the Resource's sound property.

Volume

Volume can be set initially by using the object constructor

Volume can also be set by changing the volume property.

Events

Preloaded sounds return a SoundInstance object which can be used to listen to playback events such as a the progress and end.

Library

Library is the simplest way to create a cache of sounds.

Library utilities are available to help manage the cache of sounds.

Couple of convenience methods (find, exist, duration) for manipulating and checking sounds.

Utilities

First setup an Application to render the waveform.

Create a simple sine-wave tone.

There's a utility method for playing a sound once. It is immediately destroyed and after this.

Stream

You can get the audio stream by StreamFilter