web-audio-api icon indicating copy to clipboard operation
web-audio-api copied to clipboard

AudioContext's decodeAudioData() doesn't return a Promise when a callback is not given.

Open Type1J opened this issue 2 years ago • 0 comments

From what I can tell, this is already fixed, but there's been no release for a long time. I'll drop my polyfill that monkey patches this functionality into version 0.2.2, which is what you get from npm, right now.

import { AudioContext } from "web-audio-api";

export function installPolyfill() {
  function decodeAudioData_polyfill(audioData, successCallback, errorCallback) {
    if (arguments.length > 1) {
      // Callback
      this.decodeAudioData(audioData, successCallback, errorCallback);
    } else {
      // Promise
      return new Promise((success, reject) => this.decodeAudioData_original(audioData, success, reject));
    }   
  }
  if (!AudioContext.prototype.decodeAudioData_original) {
    AudioContext.prototype.decodeAudioData_original = AudioContext.prototype.decodeAudioData;
    AudioContext.prototype.decodeAudioData = decodeAudioData_polyfill;
  }
}

Please release sometime soon. Until then, please leave this issue open, so that someone having this problem can find this solution.

Type1J avatar Jun 21 '23 13:06 Type1J