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.
+24 -7
View File
@@ -330,6 +330,8 @@ module Phaser {
case 'audio':
file.url = this.getAudioURL(file.url);
console.log('Loader audio');
console.log(file.url);
if (file.url !== null)
{
@@ -344,13 +346,27 @@ module Phaser {
}
else if (this._game.sound.usingAudioTag)
{
file.data = new Audio();
file.data.name = file.key;
file.data.onerror = () => this.fileError(file.key);
file.data.preload = 'auto';
file.data.src = file.url;
file.data.addEventListener('canplaythrough', () => this.fileComplete(file.key), false);
file.data.load();
if (this._game.sound.touchLocked)
{
// If audio is locked we can't do this yet, so need to queue this load request somehow. Bum.
console.log('Audio is touch locked');
file.data = new Audio();
file.data.name = file.key;
file.data.preload = 'auto';
file.data.src = file.url;
this.fileComplete(file.key);
}
else
{
console.log('Audio not touch locked');
file.data = new Audio();
file.data.name = file.key;
file.data.onerror = () => this.fileError(file.key);
file.data.preload = 'auto';
file.data.src = file.url;
file.data.addEventListener('canplaythrough', () => this.fileComplete(file.key), false);
file.data.load();
}
}
}
@@ -379,6 +395,7 @@ module Phaser {
if (this._game.device.canPlayAudio(extension))
{
console.log('getAudioURL', urls[i]);
console.log(urls[i]);
return urls[i];
}