Skip to content

Commit

Permalink
Fixed DOMException when play request gets interrupted by a call to pa…
Browse files Browse the repository at this point in the history
…use.
  • Loading branch information
franzformeren committed Jun 28, 2019
1 parent fc6776d commit 04b7a28
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/workspace_audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,12 @@ 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();
// If we don't wait for the play request to complete before calling pause() we will get an exception:
// Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause().
// See more: https://developers.google.com/web/updates/2017/06/play-request-was-interrupted
sound.play().then(sound.pause).catch(() => {
// Play without user interaction was prevented.
});
// 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

0 comments on commit 04b7a28

Please sign in to comment.