mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2024-12-22 14:02:29 -05:00
sounds stop and restart when played again
This commit is contained in:
parent
0742e8e0b0
commit
7f741a509c
2 changed files with 9 additions and 5 deletions
|
@ -6,6 +6,7 @@ function SoundPlayer () {
|
|||
this.buffer; // a Tone.Buffer
|
||||
this.bufferSource;
|
||||
this.playbackRate = 1;
|
||||
this.isPlaying = false;
|
||||
}
|
||||
SoundPlayer.prototype.connect = function (node) {
|
||||
this.outputNode = node;
|
||||
|
|
13
src/index.js
13
src/index.js
|
@ -144,7 +144,6 @@ function AudioPlayer (audioEngine) {
|
|||
|
||||
AudioPlayer.prototype.playSound = function (md5) {
|
||||
// if this sprite or clone is already playing this sound, stop it first
|
||||
// (this is not working, not sure why)
|
||||
if (this.activeSoundPlayers[md5]) {
|
||||
this.activeSoundPlayers[md5].stop();
|
||||
}
|
||||
|
@ -159,10 +158,14 @@ AudioPlayer.prototype.playSound = function (md5) {
|
|||
// add it to the list of active sound players
|
||||
this.activeSoundPlayers[md5] = player;
|
||||
|
||||
// when the sound completes, remove it from the list of active sound players
|
||||
return player.finished().then(() => {
|
||||
delete this.activeSoundPlayers[md5];
|
||||
});
|
||||
// remove sounds that are not playing from the active sound players array
|
||||
for (var id in this.activeSoundPlayers) {
|
||||
if (!this.activeSoundPlayers[id].isPlaying) {
|
||||
delete this.activeSoundPlayers[id];
|
||||
}
|
||||
}
|
||||
|
||||
return player.finished();
|
||||
};
|
||||
|
||||
AudioPlayer.prototype.playDrumForBeats = function (drum, beats) {
|
||||
|
|
Loading…
Reference in a new issue