2018-01-08 18:47:13 +00:00
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var BaseSound = require('../BaseSound');
|
|
|
|
var HTML5AudioSound = new Class({
|
|
|
|
Extends: BaseSound,
|
|
|
|
initialize: function HTML5AudioSound(manager, key, config) {
|
|
|
|
if (config === void 0) { config = {}; }
|
2018-01-11 16:35:25 +00:00
|
|
|
/**
|
|
|
|
* An array containing all HTML5 Audio tags that could be used for individual
|
|
|
|
* sound's playback. Number of instances depends on the config value passed
|
|
|
|
* to the Loader#audio method call, default is 1.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @property {HTMLAudioElement[]} tags
|
|
|
|
*/
|
|
|
|
this.tags = manager.game.cache.audio.get(key);
|
2018-01-11 16:36:51 +00:00
|
|
|
if (!this.tags) {
|
|
|
|
console.error('No audio loaded in cache with key: \'' + key + '\'!');
|
|
|
|
return;
|
|
|
|
}
|
2018-01-08 18:54:40 +00:00
|
|
|
/**
|
2018-01-11 16:37:28 +00:00
|
|
|
* Reference to an HTML5 Audio tag used for playing sound.
|
2018-01-08 18:54:40 +00:00
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @property {HTMLAudioElement} audio
|
|
|
|
* @default null
|
|
|
|
*/
|
2018-01-08 18:54:15 +00:00
|
|
|
this.audio = null;
|
2018-01-11 16:38:47 +00:00
|
|
|
this.duration = this.tags[0].duration;
|
|
|
|
this.totalDuration = this.tags[0].duration;
|
2018-01-08 18:47:13 +00:00
|
|
|
BaseSound.call(this, manager, key, config);
|
2018-01-11 16:40:59 +00:00
|
|
|
},
|
|
|
|
play: function (markerName, config) {
|
|
|
|
if (!BaseSound.prototype.play.call(this, markerName, config)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// TODO implement play method
|
|
|
|
this.events.dispatch(new SoundEvent(this, 'SOUND_PLAY'));
|
|
|
|
return true;
|
2018-01-08 18:47:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
module.exports = HTML5AudioSound;
|