From 1d414dd5a0b74ba20907bd1f15823c87c4c6cecd Mon Sep 17 00:00:00 2001 From: Corey Frang Date: Thu, 8 Mar 2018 12:32:01 -0500 Subject: [PATCH] Ensure music extension _decodeSound is promise Currently if there is no audio engine detected this returns undefined, which in turn causes the line above to fail trying to call `.then` on it. --- src/extensions/scratch3_music/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/extensions/scratch3_music/index.js b/src/extensions/scratch3_music/index.js index aa1d1314f..99912a94c 100644 --- a/src/extensions/scratch3_music/index.js +++ b/src/extensions/scratch3_music/index.js @@ -125,10 +125,11 @@ class Scratch3MusicBlocks { * @return {Promise} - a promise which will resolve once the sound has decoded. */ _decodeSound (soundBuffer) { - if (!this.runtime.audioEngine) return; - if (!this.runtime.audioEngine.audioContext) return; + const context = this.runtime.audioEngine && this.runtime.audioEngine.audioContext; - const context = this.runtime.audioEngine.audioContext; + if (!context) { + return Promise.reject(new Error('No Audio Context Detected')); + } // Check for newer promise-based API if (context.decodeAudioData.length === 1) {