Time to play

Audio can be loaded in two different ways, as follows:

The audio.loadSound() function loads an entire file completely into the memory and returns a reference to the audio data. Files that are loaded completely into the memory can be reused, played, and shared simultaneously on multiple channels. So, you only need to load one instance of the file. Sounds that you would use as sound effects in your game will fit in this category.

The syntax is audio.loadSound(audiofileName [, baseDir ]).

The parameters are as follows:

For example:

The audio.loadStream() function loads a file to be read as a stream. Streamed files are read in small chunks at a time to minimize memory use. Files that are large in size and have a long duration would be ideal for this. These files cannot be shared simultaneously across multiple channels. If need be, you must load multiple instances of the file.

The syntax is audio.loadStream( audioFileName [, baseDir ] )

The parameters are as follows:

For example:

The audio.play() function plays the audio specified by the audio handle on a channel. If a channel is not specified, an available channel will be automatically chosen for you. The function returns the channel number the audio is playing on.

The syntax is audio.play( audioHandle [, options ] )

The parameters are as follows:

Parameters for options:

For example:

Highly compressed formats, such as MP3, AAC, and Ogg Vorbis, can remove samples at the end of an audio sample and possibly break a clip that is looped correctly. If you experience gaps in looping during playback, try using WAV (compatible with iOS and Android). Make sure your lead-in and ending points are clean.

Sounds loaded via loadSound() can be played back simultaneously on multiple channels. For example, you can load a sound effect as follows:

If you want to make a variety of bell sounds to occur for multiple objects, you can. The audio engine is highly optimized to handle this case. Call audio.play() using that same handle as many times as you need it (up to the maximum channels):