Loader#audio()

audio(key, urls, autoDecode) → {Phaser.Loader}

Adds an audio file to the current load queue.

The file is not loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts.

The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.

Retrieve the file via Cache.getSound(key).

The URL can be relative or absolute. If the URL is relative the Loader.baseURL and Loader.path values will be prepended to it.

Mobile warning: There are some mobile devices (certain iPad 2 and iPad Mini revisions) that cannot play 48000 Hz audio.
When they try to play the audio becomes extremely distorted and buzzes, eventually crashing the sound system.
The solution is to use a lower encoding rate such as 44100 Hz.

Parameters
Name Type Argument Default Description
key string

Unique asset key of the audio file.

urls string | Array.<string> | Array.<object>

Either a single string or an array of URIs or pairs of {uri: .., type: ..}.
If an array is specified then the first URI (or URI + mime pair) that is device-compatible will be selected.
For example: "jump.mp3", ['jump.mp3', 'jump.ogg', 'jump.m4a'], or [{uri: "data:<opus_resource>", type: 'opus'}, 'fallback.mp3'].
BLOB and DATA URIs can be used but only support automatic detection when used in the pair form; otherwise the format must be manually checked before adding the resource.

autoDecode boolean <optional>
true

When using Web Audio the audio files can either be decoded at load time or run-time.
Audio files can't be played until they are decoded and, if specified, this enables immediate decoding. Decoding is a non-blocking async process, however it consumes huge amounts of CPU time on mobiles especially.

Returns

This Loader instance.

Source code: loader/Loader.js (Line 991)
doc_phaser
2017-02-14 10:54:17
Comments
Leave a Comment

Please login to continue.