Added ability for full Audio tag playback and iOS touch lock load support.

This commit is contained in:
Richard Davey
2013-07-16 23:32:47 +01:00
parent 72eb22128f
commit a2c756e37f
11 changed files with 620 additions and 215 deletions
+46 -2
View File
@@ -124,15 +124,43 @@ module Phaser {
*/
public addSound(key: string, url: string, data, webAudio: bool = true, audioTag: bool = false) {
console.log('Cache addSound', key, url, webAudio, audioTag);
console.log('Cache addSound: ' + key + ' url: ' + url, webAudio, audioTag);
var locked: bool = this._game.sound.touchLocked;
var decoded: bool = false;
if (audioTag) {
decoded = true;
}
this._sounds[key] = { url: url, data: data, isDecoding: false, decoded: decoded, webAudio: webAudio, audioTag: audioTag };
this._sounds[key] = { url: url, data: data, locked: locked, isDecoding: false, decoded: decoded, webAudio: webAudio, audioTag: audioTag };
}
public reloadSound(key: string) {
console.log('reloadSound', key);
if (this._sounds[key])
{
this._sounds[key].data.src = this._sounds[key].url;
this._sounds[key].data.addEventListener('canplaythrough', () => this.reloadSoundComplete(key), false);
this._sounds[key].data.load();
}
}
public onSoundUnlock: Phaser.Signal = new Phaser.Signal;
public reloadSoundComplete(key: string) {
console.log('reloadSoundComplete', key);
if (this._sounds[key])
{
this._sounds[key].locked = false;
this.onSoundUnlock.dispatch(key);
}
}
@@ -265,6 +293,22 @@ module Phaser {
}
/**
* Check whether an asset is decoded sound.
* @param key Asset key of the sound you want.
* @return {object} The sound data you want.
*/
public isSoundReady(key: string): bool {
if (this._sounds[key] && this._sounds[key].decoded == true && this._sounds[key].locked == false)
{
return true;
}
return false;
}
/**
* Check whether an asset is sprite sheet.
* @param key Asset key of the sprite sheet you want.