Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Type1J opened this issue Jun 21, 2023 · 0 comments

Comments

@Type1J
Copy link

Type1J commented Jun 21, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant