From 6f32a0bec7869bd6d0085330fda51687ee3ffc62 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Tue, 8 Jan 2019 11:28:40 -0500 Subject: [PATCH] Handle empty sounds --- src/AudioEngine.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/AudioEngine.js b/src/AudioEngine.js index db3ddad..c4e5805 100644 --- a/src/AudioEngine.js +++ b/src/AudioEngine.js @@ -154,6 +154,11 @@ class AudioEngine { // decoder If that fails, attempt to decode as ADPCM const decoding = decodeAudioData(this.audioContext, bufferCopy1) .catch(() => { + // If the file is empty, create an empty sound + if (sound.data.length === 0) { + return Promise.resolve(this.audioContext.createBuffer(1, 1, this.audioContext.sampleRate)); + } + // The audio context failed to parse the sound data // we gave it, so try to decode as 'adpcm'