diff --git a/src/js/audio.js b/src/js/audio.js index 5812067b..e102fa47 100644 --- a/src/js/audio.js +++ b/src/js/audio.js @@ -8,9 +8,20 @@ */ class Audio { constructor() { - this.AudioContext = window['AudioContext'] || window['webkitAudioContext']; - this.audioContext = new AudioContext(); - this.compressor = this.compressorSetup(this.audioContext); + this.fixAudioContext(); + } + + fixAudioContext() { + if (!this.audioContext) { + this.AudioContext = + window['AudioContext'] || window['webkitAudioContext']; + this.audioContext = new AudioContext(); + this.compressor = this.compressorSetup(this.audioContext); + } else if (this.audioContext.state === 'suspended') { + this.audioContext.resume().then(() => { + console.log('AudioContext resumed'); + }); + } } /** @@ -38,11 +49,6 @@ class Audio { * Triggers playOscillator() with the correct parameters. */ playTone(params = null) { - // workaround for FF starting audio context in a suspended state - if (this.audioContext.state === 'suspended') { - this.audioContext.resume(); - } - let currentDuration = constants.duration; let volume = constants.vol; if (params != null) { diff --git a/src/js/display.js b/src/js/display.js index 32f9c542..4e5c3852 100644 --- a/src/js/display.js +++ b/src/js/display.js @@ -168,6 +168,10 @@ class Display { this.announceText(resources.GetString('son_off')); } } + + if (constants.sonifMode != 'off') { + audio.fixAudioContext(); + } } /**