Handle empty sounds

This commit is contained in:
Eric Rosenbaum 2019-01-08 11:28:40 -05:00
parent 0ee5fb95c3
commit 6f32a0bec7

View file

@ -154,6 +154,11 @@ class AudioEngine {
// decoder If that fails, attempt to decode as ADPCM // decoder If that fails, attempt to decode as ADPCM
const decoding = decodeAudioData(this.audioContext, bufferCopy1) const decoding = decodeAudioData(this.audioContext, bufferCopy1)
.catch(() => { .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 // The audio context failed to parse the sound data
// we gave it, so try to decode as 'adpcm' // we gave it, so try to decode as 'adpcm'