loadFromFile method
- String path,
- Loader loadingInfo,
- 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.
- On successful fetch and decode, state becomes LoadingState.ready and buffer will contain the decoded audio.
- If fetching the file fails, state becomes LoadingState.error.
- If decoding the fetched data fails, state also becomes LoadingState.error.
Parameters:
path
: The URL or local path to the audio file.loadingInfo
: A Loader instance (frombullseye
) 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;
},
);
}