From 3610ac8ba4dff9d674d3bc2fd998f0ce9f979852 Mon Sep 17 00:00:00 2001 From: sara-fs Date: Wed, 8 Dec 2021 15:25:32 +0330 Subject: [PATCH 1/9] Checked play promise --- src/botPage/view/blockly/customBlockly.js | 11 +++++++++-- src/botPage/view/logger.js | 9 ++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/botPage/view/blockly/customBlockly.js b/src/botPage/view/blockly/customBlockly.js index a2da174a43..490823da29 100644 --- a/src/botPage/view/blockly/customBlockly.js +++ b/src/botPage/view/blockly/customBlockly.js @@ -368,8 +368,15 @@ Blockly.WorkspaceAudio.prototype.preload = function() { for (var name in this.SOUNDS_) { var sound = this.SOUNDS_[name]; sound.volume = 0.01; - sound.play().catch(function() {}); - sound.pause(); + const playPromise = sound.play(); + if (playPromise !== undefined) { + playPromise + .then(() => { + sound.pause(); + }) + .catch(() => {}); + } + // iOS can only process one sound at a time. Trying to load more than one // corrupts the earlier ones. Just load one and leave the others uncached. if (goog.userAgent.IPAD || goog.userAgent.IPHONE) { diff --git a/src/botPage/view/logger.js b/src/botPage/view/logger.js index c7168a5aa3..8eb246cf67 100644 --- a/src/botPage/view/logger.js +++ b/src/botPage/view/logger.js @@ -20,9 +20,16 @@ const notify = ({ className, message, position = 'left', sound = 'silent' }) => $.notify(message.toString(), { position: `bottom ${position}`, className }); if (sound !== 'silent') { - $(`#${sound}`) + const playPromise = $(`#${sound}`) .get(0) .play(); + if (playPromise !== undefined) { + playPromise + .then(() => { + sound.pause(); + }) + .catch(() => {}); + } } }; From eef67f426b7758eccf1e62fdbd16c7410144bba9 Mon Sep 17 00:00:00 2001 From: sara-fs Date: Thu, 9 Dec 2021 12:25:12 +0330 Subject: [PATCH 2/9] Added comment --- src/botPage/view/blockly/customBlockly.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/botPage/view/blockly/customBlockly.js b/src/botPage/view/blockly/customBlockly.js index 490823da29..06f202149f 100644 --- a/src/botPage/view/blockly/customBlockly.js +++ b/src/botPage/view/blockly/customBlockly.js @@ -368,6 +368,11 @@ Blockly.WorkspaceAudio.prototype.preload = function() { for (var name in this.SOUNDS_) { var sound = this.SOUNDS_[name]; sound.volume = 0.01; + + // A play() call on an a