Skip to content

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

@Type1J

Description

@Type1J

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions