Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Sara / Checked play promise #3487

Merged
merged 9 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/botPage/view/blockly/customBlockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,41 @@ Blockly.Toolbox.TreeNode.prototype.onClick_ = function(_e) {
* Preload all the audio files so that they play quickly when asked for.
* @package
*/

Blockly.WorkspaceAudio.prototype.load = function(filenames, name) {
if (!filenames.length) {
return;
}
try {
var audioTest = new window['Audio']();
} catch (e) {
return;
}
let sound;

filenames.forEach(filename => {
if (filename.includes('delete') || filename.includes('click') || filename.includes('disconnect')) {
filename = filename.replace('https://blockly-demo.appspot.com/static/media/', 'sound/');
}
let ext = filename.match(/\.(\w+)$/);
if (ext && audioTest.canPlayType('audio/' + ext[1])) {
sound = new window['Audio'](filename);
}
});
if (sound?.play) {
this.SOUNDS_[name] = sound;
}
};
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();
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) {
Expand Down
9 changes: 8 additions & 1 deletion src/botPage/view/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {});
}
}
};

Expand Down
Binary file modified static/.DS_Store
Binary file not shown.
Binary file added static/sound/click.mp3
Binary file not shown.
Binary file added static/sound/click.ogg
Binary file not shown.
Binary file added static/sound/click.wav
Binary file not shown.
Binary file added static/sound/delete.mp3
Binary file not shown.
Binary file added static/sound/delete.ogg
Binary file not shown.
Binary file added static/sound/delete.wav
Binary file not shown.
Binary file added static/sound/disconnect.mp3
Binary file not shown.
Binary file added static/sound/disconnect.ogg
Binary file not shown.
Binary file added static/sound/disconnect.wav
Binary file not shown.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy