decodeAudioData method

JSPromise<AudioBuffer> decodeAudioData(
  1. JSArrayBuffer audioData, [
  2. DecodeSuccessCallback? successCallback,
  3. DecodeErrorCallback? errorCallback
])

The decodeAudioData() method of the BaseAudioContext Interface is used to asynchronously decode audio file data contained in an ArrayBuffer that is loaded from fetch, XMLHttpRequest, or FileReader. The decoded AudioBuffer is resampled to the AudioContext's sampling rate, then passed to a callback or promise.

This is the preferred method of creating an audio source for Web Audio API from an audio track. This method only works on complete file data, not fragments of audio file data.

This function implements two alternative ways to asynchronously return the audio data or error messages: it returns a Promise that fulfills with the audio data, and also accepts callback arguments to handle success or failure. The primary method of interfacing with this function is via its Promise return value, and the callback parameters are provided for legacy reasons.

Implementation

external JSPromise<AudioBuffer> decodeAudioData(
  JSArrayBuffer audioData, [
  DecodeSuccessCallback? successCallback,
  DecodeErrorCallback? errorCallback,
]);