loadFromFile method

dynamic loadFromFile(
  1. String path,
  2. Loader loadingInfo,
  3. AudioContext audioContext
)

Asynchronously loads a sound from a file at the given path.

This method uses the bullseye package's load function to fetch the audio file as an ArrayBuffer. Upon successful fetching, it then calls loadFromBytes to decode the audio data.

Parameters:

  • path: The URL or local path to the audio file.
  • loadingInfo: A Loader instance (from bullseye) to manage and track the loading progress and status of the external resource.
  • audioContext: The Web Audio API AudioContext used to decode the audio data.

Implementation

loadFromFile(String path, Loader loadingInfo, AudioContext audioContext) {
  load<JSArrayBuffer?>(
    path,
    loadingInfo,
    responseType: "arraybuffer",
    onLoad: (response, complete, error) async {
      var audioBytes = (response as JSArrayBuffer);
      await loadFromBytes(audioBytes, audioContext);
      complete(audioBytes);
    },
    onError: (event) {
      state = LoadingState.error;
    },
  );
}