This commit is contained in:
Richard Davey 2018-04-15 05:05:09 +01:00
commit 02be81cc48
7 changed files with 66 additions and 25 deletions

View file

@ -16,6 +16,7 @@
* Fixed issue in HTMLAudioSound where `mute` would get into a recursive loop.
* Every RenderTexture would draw the same content due to a mis-use of the CanvasPool (this also impacted TileSprites). Fix #3555 (thanks @kuoruan)
* Group.add and Group.addMultiple now respect the Group.maxSize property, stopping you from over-populating a Group (thanks @samme)
* When using HTML5 Audio, sound manager now tries to unlock audio after every scene loads, instead of only after first one. Fix #3309 (thanks @pavle-goloskokovic)
### Updates

View file

@ -122,7 +122,7 @@ AudioFile.create = function (loader, key, urls, config, xhrSettings)
}
else
{
return new HTML5AudioFile(key, url, loader.path, config, game.sound.locked);
return new HTML5AudioFile(key, url, loader.path, config);
}
};

View file

@ -23,7 +23,6 @@ var GetURL = require('../GetURL');
* @param {string} url - [description]
* @param {string} path - [description]
* @param {XHRSettingsObject} config - [description]
* @param {boolean} locked - [description]
*/
var HTML5AudioFile = new Class({
@ -31,9 +30,9 @@ var HTML5AudioFile = new Class({
initialize:
function HTML5AudioFile (key, url, path, config, locked)
function HTML5AudioFile (key, url, path, config)
{
this.locked = locked;
this.locked = 'ontouchstart' in window;
this.loaded = false;
@ -110,8 +109,14 @@ var HTML5AudioFile = new Class({
audio.dataset.name = this.key + ('0' + i).slice(-2); // Useful for debugging
audio.dataset.used = 'false';
if (!this.locked)
if (this.locked)
{
audio.dataset.locked = 'true';
}
else
{
audio.dataset.locked = 'false';
audio.preload = 'auto';
audio.oncanplaythrough = this.onProgress.bind(this);
audio.onerror = this.onError.bind(this);

View file

@ -499,6 +499,12 @@ var SceneManager = new Class({
{
var scene = loader.scene;
// Try to unlock HTML5 sounds every time any loader completes
if (this.game.sound.onBlurPausedSounds)
{
this.game.sound.unlock();
}
this.create(scene);
},

View file

@ -31,9 +31,9 @@ var NOOP = require('../utils/NOOP');
* @classdesc
* The sound manager is responsible for playing back audio via Web Audio API or HTML Audio tag as fallback.
* The audio file type and the encoding of those files are extremely important.
*
*
* Not all browsers can play all audio formats.
*
*
* There is a good guide to what's supported [here](https://developer.mozilla.org/en-US/Apps/Fundamentals/Audio_and_video_delivery/Cross-browser_audio_basics#Audio_Codec_Support).
*
* @class BaseSoundManager
@ -169,11 +169,6 @@ var BaseSoundManager = new Class({
* @since 3.0.0
*/
this.unlocked = false;
if (this.locked)
{
this.unlock();
}
},
/**
@ -537,7 +532,7 @@ var BaseSoundManager = new Class({
/**
* Sets the global playback rate at which all the sounds will be played.
*
*
* For example, a value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed
* and 2.0 doubles the audios playback speed.
*

View file

@ -96,7 +96,7 @@ var HTML5AudioSoundManager = new Class({
* @private
* @since 3.0.0
*/
this.lockedActionsQueue = this.locked ? [] : null;
this.lockedActionsQueue = null;
/**
* Property that actually holds the value of global mute
@ -154,6 +154,17 @@ var HTML5AudioSoundManager = new Class({
*/
unlock: function ()
{
this.locked = 'ontouchstart' in window;
if(this.locked)
{
this.lockedActionsQueue = [];
}
else
{
return;
}
var _this = this;
var moved = false;
@ -165,11 +176,6 @@ var HTML5AudioSoundManager = new Class({
var unlock = function ()
{
if (!_this.game.cache.audio.entries.size)
{
return;
}
if (moved)
{
moved = false;
@ -179,26 +185,43 @@ var HTML5AudioSoundManager = new Class({
document.body.removeEventListener('touchmove', detectMove);
document.body.removeEventListener('touchend', unlock);
var allTags = [];
var lockedTags = [];
_this.game.cache.audio.entries.each(function (key, tags)
{
for (var i = 0; i < tags.length; i++)
{
allTags.push(tags[i]);
var tag = tags[i];
if (tag.dataset.locked === 'true')
{
lockedTags.push(tag);
}
}
return true;
});
var lastTag = allTags[allTags.length - 1];
if (lockedTags.length === 0)
{
return;
}
var lastTag = lockedTags[lockedTags.length - 1];
lastTag.oncanplaythrough = function ()
{
lastTag.oncanplaythrough = null;
lockedTags.forEach(function (tag)
{
tag.dataset.locked = 'false';
});
_this.unlocked = true;
};
allTags.forEach(function (tag)
lockedTags.forEach(function (tag)
{
tag.load();
});
@ -208,7 +231,11 @@ var HTML5AudioSoundManager = new Class({
{
this.forEachActiveSound(function (sound)
{
sound.duration = sound.tags[0].duration;
if(sound.currentMarker === null && sound.duration === 0)
{
sound.duration = sound.tags[0].duration;
}
sound.totalDuration = sound.tags[0].duration;
});
@ -226,6 +253,7 @@ var HTML5AudioSoundManager = new Class({
this.lockedActionsQueue.length = 0;
this.lockedActionsQueue = null;
}, this);
document.body.addEventListener('touchmove', detectMove, false);
@ -302,7 +330,7 @@ var HTML5AudioSoundManager = new Class({
*/
isLocked: function (sound, prop, value)
{
if (this.locked)
if (sound.tags[0].dataset.locked === 'true')
{
this.lockedActionsQueue.push({
sound: sound,

View file

@ -76,6 +76,11 @@ var WebAudioSoundManager = new Class({
this.locked = this.context.state === 'suspended' && 'ontouchstart' in window;
BaseSoundManager.call(this, game);
if (this.locked)
{
this.unlock();
}
},
/**
@ -145,6 +150,7 @@ var WebAudioSoundManager = new Class({
{
document.body.removeEventListener('touchstart', unlock);
document.body.removeEventListener('touchend', unlock);
_this.unlocked = true;
});
};