Last active
November 16, 2021 13:01
-
-
Save beefchimi/432ce53f7d24aa0896eb96d75fe5299b to your computer and use it in GitHub Desktop.
Fetch audio buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function fetchAudioBuffer(path, context) { | |
const audioRequest = new Request(path); | |
return fetch(audioRequest).then((response) => { | |
return response.arrayBuffer(); | |
}).then((arrayBuffer) => { | |
return context.decodeAudioData(arrayBuffer); | |
}).catch((error) => { | |
throw Error(`Asset failed to load: ${error.message}`); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment