Prevent sounds from playing on top of each other.

This commit is contained in:
Neil Fraser
2016-05-21 05:55:24 -07:00
parent 28188d8bf3
commit 006bb36b89
3 changed files with 20 additions and 0 deletions

View File

@@ -982,6 +982,7 @@ Blockly.BlockSvg.prototype.getSvgRoot = function() {
* @param {boolean} animate If true, show a disposal animation and sound.
*/
Blockly.BlockSvg.prototype.dispose = function(healStack, animate) {
Blockly.Tooltip.hide();
Blockly.Field.startCache();
// If this block is being dragged, unlink the mouse events.
if (Blockly.selected == this) {

View File

@@ -52,6 +52,12 @@ Blockly.COLLAPSE_CHARS = 30;
*/
Blockly.LONGPRESS = 750;
/**
* Prevent a sound from playing if another sound preceded it within this many
* miliseconds.
*/
Blockly.SOUND_LIMIT = 100;
/**
* The richness of block colours, regardless of the hue.
* Must be in the range of 0 (inclusive) to 1 (exclusive).

View File

@@ -131,6 +131,13 @@ Blockly.WorkspaceSvg.prototype.trashcan = null;
*/
Blockly.WorkspaceSvg.prototype.scrollbar = null;
/**
* Time that the last sound was played.
* @type {Date}
* @private
*/
Blockly.WorkspaceSvg.prototype.lastSound_ = null;
/**
* Create the workspace DOM elements.
* @param {string=} opt_backgroundClass Either 'blocklyMainBackground' or
@@ -904,6 +911,12 @@ Blockly.WorkspaceSvg.prototype.preloadAudio_ = function() {
Blockly.WorkspaceSvg.prototype.playAudio = function(name, opt_volume) {
var sound = this.SOUNDS_[name];
if (sound) {
// Don't play one sound on top of another.
var now = new Date();
if (now - this.lastSound_ < Blockly.Blockly.SOUND_LIMIT) {
return;
}
this.lastSound_ = now;
var mySound;
var ie9 = goog.userAgent.DOCUMENT_MODE &&
goog.userAgent.DOCUMENT_MODE === 9;