mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2024-12-22 14:02:29 -05:00
playsound returns promise for completion
This commit is contained in:
parent
f8aaf553f8
commit
e3276c80d5
1 changed files with 5 additions and 0 deletions
|
@ -68,6 +68,11 @@ AudioEngine.prototype.playSound = function (index) {
|
||||||
var player = this.soundPlayers[index];
|
var player = this.soundPlayers[index];
|
||||||
if (player && player.buffer.loaded) {
|
if (player && player.buffer.loaded) {
|
||||||
player.start();
|
player.start();
|
||||||
|
return new Promise(function (resolve) {
|
||||||
|
setTimeout(function () {
|
||||||
|
resolve();
|
||||||
|
}, (player.buffer.duration * 1000) / player.playbackRate);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// if the sound has not yet loaded, wait and try again
|
// if the sound has not yet loaded, wait and try again
|
||||||
log.warn('sound ' + index + ' not loaded yet');
|
log.warn('sound ' + index + ' not loaded yet');
|
||||||
|
|
Loading…
Reference in a new issue