mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Use map of soundPlayers for stop all
This commit is contained in:
parent
fb7c293e71
commit
fe746a7c43
1 changed files with 26 additions and 7 deletions
|
@ -61,12 +61,16 @@ class Scratch3SpeakBlocks {
|
||||||
*/
|
*/
|
||||||
this.runtime = runtime;
|
this.runtime = runtime;
|
||||||
|
|
||||||
// @todo stop all speech sounds currently playing
|
/**
|
||||||
// https://github.com/LLK/scratch-vm/issues/1405
|
* Map of soundPlayers by sound id.
|
||||||
// this._stopAllSpeech = this._stopAllSpeech.bind(this);
|
* @type {Map<string, SoundPlayer>}
|
||||||
// if (this.runtime) {
|
*/
|
||||||
// this.runtime.on('PROJECT_STOP_ALL', this._stopAllSpeech);
|
this._soundPlayers = new Map();
|
||||||
// }
|
|
||||||
|
this._stopAllSpeech = this._stopAllSpeech.bind(this);
|
||||||
|
if (this.runtime) {
|
||||||
|
this.runtime.on('PROJECT_STOP_ALL', this._stopAllSpeech);
|
||||||
|
}
|
||||||
|
|
||||||
this._onTargetCreated = this._onTargetCreated.bind(this);
|
this._onTargetCreated = this._onTargetCreated.bind(this);
|
||||||
if (this.runtime) {
|
if (this.runtime) {
|
||||||
|
@ -278,6 +282,15 @@ class Scratch3SpeakBlocks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop all currently playing speech sounds.
|
||||||
|
*/
|
||||||
|
_stopAllSpeech () {
|
||||||
|
this._soundPlayers.forEach(player => {
|
||||||
|
player.stop();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the provided text into a sound file and then play the file.
|
* Convert the provided text into a sound file and then play the file.
|
||||||
* @param {object} args Block arguments
|
* @param {object} args Block arguments
|
||||||
|
@ -337,6 +350,8 @@ class Scratch3SpeakBlocks {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.runtime.audioEngine.decodeSoundPlayer(sound).then(soundPlayer => {
|
this.runtime.audioEngine.decodeSoundPlayer(sound).then(soundPlayer => {
|
||||||
|
this._soundPlayers.set(soundPlayer.id, soundPlayer);
|
||||||
|
|
||||||
soundPlayer.setPlaybackRate(playbackRate);
|
soundPlayer.setPlaybackRate(playbackRate);
|
||||||
|
|
||||||
// Increase the volume
|
// Increase the volume
|
||||||
|
@ -345,7 +360,11 @@ class Scratch3SpeakBlocks {
|
||||||
chain.set('volume', 250);
|
chain.set('volume', 250);
|
||||||
soundPlayer.connect(chain);
|
soundPlayer.connect(chain);
|
||||||
|
|
||||||
soundPlayer.on('stop', resolve);
|
soundPlayer.play();
|
||||||
|
soundPlayer.on('stop', () => {
|
||||||
|
this._soundPlayers.delete(soundPlayer.id);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue