2018-01-08 18:25:11 +00:00
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var BaseSoundManager = require('../BaseSoundManager');
|
2018-01-08 18:26:32 +00:00
|
|
|
var HTML5AudioSound = require('./HTML5AudioSound');
|
2018-01-08 18:25:11 +00:00
|
|
|
var HTML5AudioSoundManager = new Class({
|
|
|
|
Extends: BaseSoundManager,
|
|
|
|
initialize: function HTML5AudioSoundManager(game) {
|
2018-01-08 18:27:44 +00:00
|
|
|
this.onBlurPausedSounds = [];
|
2018-01-08 18:30:42 +00:00
|
|
|
this._mute = false;
|
2018-01-08 18:25:11 +00:00
|
|
|
BaseSoundManager.call(this, game);
|
2018-01-08 18:26:32 +00:00
|
|
|
},
|
|
|
|
add: function (key, config) {
|
|
|
|
var sound = new HTML5AudioSound(this, key, config);
|
|
|
|
this.sounds.push(sound);
|
|
|
|
return sound;
|
2018-01-08 18:28:21 +00:00
|
|
|
},
|
|
|
|
onBlur: function () {
|
|
|
|
this.forEachActiveSound(function (sound) {
|
|
|
|
if (sound.isPlaying) {
|
|
|
|
this.onBlurPausedSounds.push(sound);
|
|
|
|
sound.pause();
|
|
|
|
}
|
|
|
|
});
|
2018-01-08 18:29:01 +00:00
|
|
|
},
|
|
|
|
onFocus: function () {
|
|
|
|
this.onBlurPausedSounds.forEach(function (sound) {
|
|
|
|
sound.resume();
|
|
|
|
});
|
|
|
|
this.onBlurPausedSounds.length = 0;
|
2018-01-08 18:29:16 +00:00
|
|
|
},
|
|
|
|
destroy: function () {
|
|
|
|
BaseSoundManager.prototype.destroy.call(this);
|
|
|
|
this.onBlurPausedSounds.length = 0;
|
|
|
|
this.onBlurPausedSounds = null;
|
2018-01-08 18:25:11 +00:00
|
|
|
}
|
|
|
|
});
|
2018-01-08 18:31:26 +00:00
|
|
|
Object.defineProperty(HTML5AudioSoundManager.prototype, 'mute', {
|
|
|
|
get: function () {
|
|
|
|
},
|
|
|
|
set: function (value) {
|
|
|
|
}
|
|
|
|
});
|
2018-01-08 18:25:11 +00:00
|
|
|
module.exports = HTML5AudioSoundManager;
|