Loading Audio

Supported Formats

For iOS and Android, only WAV and OGG formats are supported.

For PC (Windows, Linux, MacOSX), with the FFMpeg extensions, all audio formats supported by FFMpeg can be loaded.


Use the following to load an audio file:

Audio mymusic = Audio.Load("myaudiofile.ogg");

This loads in the audio file as a single contiguous stream.

To load a file in pieces, specify an additional parameter, the chunk size:

Audio mymusic = Audio.Load("myaudiofile.ogg",64000);

This will load the audio into the audio playback buffers in chunks of up to 64000 in size. This is useful for longer files, files downloaded from the internet, or ogg files where the decoding takes a relatively long time.

Audio is always loaded in a background thread.

To load audio from the internet, do:

Audio mymusic = Audio.Load("",64000);

To load audio from an embedded resource, do:

Audio mymusic = Audio.Load("embed://myaudiofile.ogg",64000);


To initiate playback, do:


This will initiate the playback in a dedicated audio playback background thread, and will play once.

For more advanced functions, don’t just call the Play() method directly. the method returns a specific audio stream class for managing the sound:

AudioStream musicplayback = mymusic.Play();

This represents a specific playback of the file, and the stream class then allows manipulation of the various audio properties:

musicplayback.Pitch = 0.25f;
musicplayback.Gain = 0.5f;    // Volume (0..1)
musicstream.State = AudioState.Paused;