I have a simple JavaScript that loads sounds:
prefix = 'modules/sounds/';
_sounds = ['nameOfSound','nameOfSound','nameOfSound'];
for (var sound in _sounds) {
if (_sounds.hasOwnProperty(sound)) {
var cached = _sounds[sound];
cached.audio = new Audio(prefix + cached.src);
}
}
}
All is being cached here, and then in angular I just have a service that does the following function:
this.play = function(trackName) {
_sounds[trackName].audio.play();
};
What I want is a simple promise for the sound, so when I call it, I will have something like this:
soundService.play('boom').then(function(){
do something here
});
Is that even possible?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…