diff --git a/src/DrumPlayer.js b/src/DrumPlayer.js index 8592321..9b021f6 100644 --- a/src/DrumPlayer.js +++ b/src/DrumPlayer.js @@ -44,7 +44,20 @@ class DrumPlayer { request.responseType = 'arraybuffer'; request.onload = () => { const audioData = request.response; - this.audioContext.decodeAudioData(audioData).then(buffer => { + // Check for newer promise-based API + let loaderPromise; + if (this.audioContext.decodeAudioData.length === 1) { + loaderPromise = this.audioContext.decodeAudioData(audioData); + } else { + // Fall back to callback API + loaderPromise = new Promise((resolve, reject) => { + this.audioContext.decodeAudioData(audioData, + decodedAudio => resolve(decodedAudio), + error => reject(error) + ); + }); + } + loaderPromise.then(buffer => { this.drumSounds[i].setBuffer(buffer); }); }; diff --git a/src/index.js b/src/index.js index a0841d9..f2c3198 100644 --- a/src/index.js +++ b/src/index.js @@ -203,7 +203,18 @@ class AudioEngine { switch (sound.format) { case '': - loaderPromise = this.audioContext.decodeAudioData(bufferCopy); + // Check for newer promise-based API + if (this.audioContext.decodeAudioData.length === 1) { + loaderPromise = this.audioContext.decodeAudioData(bufferCopy); + } else { + // Fall back to callback API + loaderPromise = new Promise((resolve, reject) => { + this.audioContext.decodeAudioData(bufferCopy, + decodedAudio => resolve(decodedAudio), + error => reject(error) + ); + }); + } break; case 'adpcm': loaderPromise = (new ADPCMSoundDecoder(this.audioContext)).decode(bufferCopy);