From e3276c80d5e0eed5730232fc7ee6a89fe1778524 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Tue, 25 Oct 2016 22:42:15 -0400 Subject: [PATCH] playsound returns promise for completion --- src/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/index.js b/src/index.js index cab8c5e..7ee7ce7 100644 --- a/src/index.js +++ b/src/index.js @@ -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');