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.
This commit is contained in:
Corey Frang 2018-03-08 12:32:01 -05:00
parent cc2bf1dfc7
commit 1d414dd5a0

View file

@ -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) {