mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Prevent sounds from playing on top of each other.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user