playsound returns promise for completion

This commit is contained in:
Eric Rosenbaum 2016-10-25 22:42:15 -04:00
parent f8aaf553f8
commit e3276c80d5

View file

@ -68,6 +68,11 @@ AudioEngine.prototype.playSound = function (index) {
var player = this.soundPlayers[index];
if (player && player.buffer.loaded) {
player.start();
return new Promise(function (resolve) {
setTimeout(function () {
resolve();
}, (player.buffer.duration * 1000) / player.playbackRate);
});
} else {
// if the sound has not yet loaded, wait and try again
log.warn('sound ' + index + ' not loaded yet');