Skip to content

Commit 599bcf5

Browse files
committed
Loader.audiosprite has a new jsonData parameter. It allows you to pass a pre-existing JSON object (or a string which will be parsed as JSON) to use as the audiosprite data, instead of specifying a URL to a JSON file on the server (thanks @jounii phaserjs#1447)
Loader.audiosprite has a new `autoDecode` parameter. If `true` the audio file will be decoded immediately upon load.
1 parent aa2df80 commit 599bcf5

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ Thanks to @pnstickne for vast majority of this update.
126126
* ArcadePhysics.distanceToPointer now calculates the distance in world space values.
127127
* Sound.fadeIn now supports fading from a marker, as well as the entire audio clip, so now works with audio sprites (thanks @vorrin #1413)
128128
* Text font components can now be specified as part of "style". There is a breaking change in that the `fontWeight` now only handles the CSS font-weight component. The `fontStyle` property handles 'italic', 'oblique', values from font-style. This makes the overall consistency cleaner but some code may need to be updated. This does not affect font-weight/font-style as with setStyle({font:..}). Also fixes overwrite font/size/weight oddities - which may result in different behavior for code that was relying on such. All of the text examples appear to work and modification using the new features (while respecting the change in previous behavior) work better (thanks @pnstickne #1375 #1370)
129+
* Loader.audiosprite has a new `jsonData` parameter. It allows you to pass a pre-existing JSON object (or a string which will be parsed as JSON) to use as the audiosprite data, instead of specifying a URL to a JSON file on the server (thanks @jounii #1447)
130+
* Loader.audiosprite has a new `autoDecode` parameter. If `true` the audio file will be decoded immediately upon load.
129131

130132
### Bug Fixes
131133

src/loader/Cache.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,15 @@ Phaser.Cache.prototype = {
538538
decoded = true;
539539
}
540540

541-
this._sounds[key] = { url: url, data: data, isDecoding: false, decoded: decoded, webAudio: webAudio, audioTag: audioTag, locked: this.game.sound.touchLocked };
541+
this._sounds[key] = {
542+
url: url,
543+
data: data,
544+
isDecoding: false,
545+
decoded: decoded,
546+
webAudio: webAudio,
547+
audioTag: audioTag,
548+
locked: this.game.sound.touchLocked
549+
};
542550

543551
this._resolveURL(url, this._sounds[key]);
544552

src/loader/Loader.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -785,14 +785,37 @@ Phaser.Loader.prototype = {
785785
* @method Phaser.Loader#audiosprite
786786
* @param {string} key - Unique asset key of the audio file.
787787
* @param {Array|string} urls - An array containing the URLs of the audio files, i.e.: [ 'audiosprite.mp3', 'audiosprite.ogg', 'audiosprite.m4a' ] or a single string containing just one URL.
788-
* @param {string} jsonURL - The URL of the audiosprite configuration json.
788+
* @param {string} [jsonURL=null] - The URL of the audiosprite configuration JSON object. If you wish to pass the data directly set this parameter to null.
789+
* @param {string|object} [jsonData=null] - A JSON object or string containing the audiosprite configuration data. This is ignored if jsonURL is not null.
790+
* @param {boolean} [autoDecode=true] - When using Web Audio the audio files can either be decoded at load time or run-time.
791+
* Audio files can't be played until they are decoded and, if specified, this enables immediate decoding. Decoding is a non-blocking async process.
789792
* @return {Phaser.Loader} This Loader instance.
790793
*/
791-
audiosprite: function(key, urls, jsonURL) {
794+
audiosprite: function(key, urls, jsonURL, jsonData, autoDecode) {
795+
796+
if (typeof jsonURL === 'undefined') { jsonURL = null; }
797+
if (typeof jsonData === 'undefined') { jsonData = null; }
798+
if (typeof autoDecode === 'undefined') { autoDecode = true; }
792799

793-
this.audio(key, urls);
800+
this.audio(key, urls, autoDecode);
801+
802+
if (jsonURL)
803+
{
804+
this.json(key + '-audioatlas', jsonURL);
805+
}
806+
else if (jsonData)
807+
{
808+
if (typeof jsonData === 'string')
809+
{
810+
jsonData = JSON.parse(jsonData);
811+
}
794812

795-
this.json(key + '-audioatlas', jsonURL);
813+
this.game.cache.addJSON(key + '-audioatlas', '', jsonData);
814+
}
815+
else
816+
{
817+
console.warn('Phaser.Loader.audiosprite - You must specify either a jsonURL or provide a jsonData object');
818+
}
796819

797820
return this;
798821

0 commit comments

Comments
 (0)