From fcbfde506abf6ca3474d2dfdf4f337b86b0bb579 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 17 Apr 2020 17:48:55 -0400 Subject: [PATCH] Await and handle errors from audio.play() --- ext/mixed/js/audio-system.js | 2 +- ext/mixed/js/display.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ext/mixed/js/audio-system.js b/ext/mixed/js/audio-system.js index 94885d34..3273f982 100644 --- a/ext/mixed/js/audio-system.js +++ b/ext/mixed/js/audio-system.js @@ -40,7 +40,7 @@ class TextToSpeechAudio { } } - play() { + async play() { try { if (this._utterance === null) { this._utterance = new SpeechSynthesisUtterance(this.text || ''); diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index f30a65e6..b4a93d99 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -823,7 +823,14 @@ class Display { this.audioPlaying = audio; audio.currentTime = 0; audio.volume = this.options.audio.volume / 100.0; - audio.play(); + const playPromise = audio.play(); + if (typeof playPromise !== 'undefined') { + try { + await playPromise; + } catch (e2) { + // NOP + } + } } catch (e) { this.onError(e); } finally {