How to play sounds and musics

Sandbox Adventure can play audio files.

You can add new CG in the admin panel in the Assets > Sounds and music menu.

In order to be compatible with every browser, every sounds and music must be available in two formats: MP3 and OGG. Indeed, the most popular audio format MPEG3 (.mp3) is not an Open standard, it is patent encumbered. That means, web browser needs to pay a sum of money in order to decode it. Therefore, this format is not supported by Firefox and Opera . They support instead only Vorbis (.ogg) format which is an Open standard. On the other hand, the open standard Vorbis (*.ogg) is not supported by Safari and Internet Explorer. Hence, it is always good to have both MP3 and OGG side to side available.

Sandbox Adventure supports an arbitrary number of audio channels. There are four normal channels defined by default:

  • music - A channel for music playback.
  • ambient - A channel for ambient playback.
  • sound - A channel for sound effects.
  • voice - A channel for voice.

Channels support playing and queueing audio, but only play back one audio file at a time.

PLAY STATEMENT

The play statement is used to play sound and music. If a file is currently playing on a normal channel, it is interrupted and replaced with the new file.

A play statement consists of a single logical line beginning with the keyword play, followed by the optional channel name, followed by the audio short code, followed by zero or more properties.

> play music traviata

Optional properties:

LOOP

This parameter defines how many times the audio files will be read.

By default, a file played on the music or ambient channels will be looped. A file played on any other channel will be played only once.

It is possible to overide this default behavior by specitying the loop parameters:

# defaut value for a music: infinite loop
> play music traviata
# infinite loop
> play music traviata loop
# no loop, the audio file will be played only once
> play music traviata loop 1
# the audio file will be played twice
> play music traviata loop 2

VOLUME

This parameter specifies the volume.

The value can be a float number between 0 and 1.

> play sound bells volume 0.5

QUEUE STATEMENT

The queue statement is used to queue up audio files. They will be played when the channel finishes playing the currently playing file.

> play music traviata
# the Tosca will be played once the Traviata is finished
> queue music tosca

STOP STATEMENT

The stop statement is used to stop playing audio files.

# stop the music channel
> stop music
# stop all channels
> stop all

Back to the beginning of the guide